Display Chart.DrawStaticText() over a Canvas Rectangle

amirus.stark since: 01 May 2020;

  01 Mar 2021, 11:02
Display Chart.DrawStaticText() over a Canvas Rectangle

Hi there, 

It's been hours since I'm trying to Display some Chart.DrawStaticText() over a Canvas Rectangle, I need to do it that way because characters have different colors, is there a way to perform this by changing Chart.DrawStaticText()'s Zindex ? if yes, how please ?

Thanks

afhacker's avatar

afhacker since: 15 Oct 2015;

  02 Mar 2021, 11:41
RE:

amirus.stark said:

Hi there, 

It's been hours since I'm trying to Display some Chart.DrawStaticText() over a Canvas Rectangle, I need to do it that way because characters have different colors, is there a way to perform this by changing Chart.DrawStaticText()'s Zindex ? if yes, how please ?

Thanks

Why you are not using text block? you are trying to mix chart objects with chart controls, Canvas is a chart control, and the Chart.DrawStaticText draws a chart object on the chart.

You have to use a chart control inside canvas not an object, try text block.

You can add multiple text blocks for each character so they will have different colors.

http://algodeveloper.com/

amirus.stark since: 01 May 2020;

  02 Mar 2021, 11:55
RE: RE:

afhacker said:

Why you are not using text block? you are trying to mix chart objects with chart controls, Canvas is a chart control, and the Chart.DrawStaticText draws a chart object on the chart.

You have to use a chart control inside canvas not an object, try text block.

You can add multiple text blocks for each character so they will have different colors.

Well basically because in the same line some characters have different colors than others and in TextBlock you can pick a color for a whole string :/

amusleh's avatar

amusleh since: 01 Mar 2021;

  03 Mar 2021, 07:46
RE: RE: RE:

amirus.stark said:

afhacker said:

Why you are not using text block? you are trying to mix chart objects with chart controls, Canvas is a chart control, and the Chart.DrawStaticText draws a chart object on the chart.

You have to use a chart control inside canvas not an object, try text block.

You can add multiple text blocks for each character so they will have different colors.

Well basically because in the same line some characters have different colors than others and in TextBlock you can pick a color for a whole string :/

You can do something like this:

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DifferentColorText : Indicator
    {
        protected override void Initialize()
        {
            var canvas = new Canvas
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center
            };

            canvas.AddChild(new TextBlock
            {
                ForegroundColor = Color.Blue,
                Text = "A ",
                Left = 10,
                Top = 15,
            });

            canvas.AddChild(new TextBlock
            {
                ForegroundColor = Color.Yellow,
                Text = "B ",
                Left = 20,
                Top = 15,
            });

            canvas.AddChild(new TextBlock
            {
                ForegroundColor = Color.Green,
                Text = "C ",
                Left = 30,
                Top = 15,
            });

            canvas.AddChild(new TextBlock
            {
                ForegroundColor = Color.Magenta,
                Text = "D",
                Left = 40,
                Top = 15,
            });

            Chart.AddControl(canvas);
        }

        public override void Calculate(int index)
        {
        }
    }
}

Or to make it easier you can create a custom control for it.

Community Developer | Spotware