Display Chart.DrawStaticText() over a Canvas Rectangle

Created at 01 Mar 2021, 11:02
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
AM

amirus.stark

Joined 01.05.2020

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


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


@amirus.stark
Replies

afhacker
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.


@afhacker

amirus.stark
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 :/

 


@amirus.stark

amusleh
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.


@amusleh