Page 1 of 1

How to draw grid lines with given values

Posted: Sun Dec 12, 2021 4:18 pm
by 21092546
Hi

I have an RSI line chart and the grid value range is from 0 - 100. I need only two grid lines with values 20 and 80. Currently the grid lines are generated automatically but not at 20 and 80.

Thanks

Larry

Re: How to draw grid lines with given values

Posted: Mon Dec 13, 2021 11:54 am
by Christopher
Hello Larry,

probably the easiest way to achieve what you want is to use 'custom labels,' e.g.

Code: Select all

        private void InitializeChart(TChart chart)
        {
            Random rnd = new();
            Line line = new(chart.Chart);
            for (int i = 0; i < 20; i++)
            {
                line.Add(rnd.Next(0, 100));
            }

            chart.Axes.Left.Grid.DrawEvery = 1;
            chart.Axes.Left.Labels.Items.Add(20, "20");
            chart.Axes.Left.Labels.Items.Add(80, "80");
        }
Which here gives me this chart:
Screenshot from 2021-12-13 12-51-53.png
Screenshot from 2021-12-13 12-51-53.png (23.91 KiB) Viewed 5069 times