CalcYPosValue returns 0

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
icecream
Newbie
Newbie
Posts: 20
Joined: Thu Aug 07, 2008 12:00 am

CalcYPosValue returns 0

Post by icecream » Thu Jul 23, 2015 1:59 pm

Hello,

There is a simple example in attachment that creates a TChart and outputs a value returned by CalcYPosValue(120) method.
This value is always 0, despite what I pass as a parameter.
So, my question is why and what should be done to make it show correct value?

Thanks.
Attachments
TeeChartExample.zip
(6.74 KiB) Downloaded 668 times

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: CalcYPosValue returns 0

Post by Christopher » Thu Jul 23, 2015 2:24 pm

Hello,

This is because the Chart needs to first render before being able to calculate this value. Until the Chart is drawn, the axes do not know where the series points are. You have a couple of options here:

Code: Select all

        public Form1()
        {
            InitializeComponent();

            TChart tchart = new TChart();
            tchart.Series.Add(new FastLine());
            tchart.Axes.Left.Automatic = false;
            tchart.Axes.Left.Minimum = 0;
            tchart.Axes.Left.Maximum = 255;
            tchart.Aspect.View3D = false;

            tchart[0].FillSampleValues();

            this.Controls.Add(tchart);

            //option 1
            /* 
            tchart.Draw(); 

            int y = tchart.Axes.Left.CalcYPosValue(120);
            label1.Text = String.Format("tchart.Chart.Axes.Left.CalcYPosValue(120) = {0}", y);
           */

            //option 2
            tchart.AfterDraw += tchart_AfterDraw;
        }

        void tchart_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
          int y = (sender as TChart).Axes.Left.CalcYPosValue(120);
          label1.Text = String.Format("tchart.Chart.Axes.Left.CalcYPosValue(120) = {0}", y);
        }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

icecream
Newbie
Newbie
Posts: 20
Joined: Thu Aug 07, 2008 12:00 am

Re: CalcYPosValue returns 0

Post by icecream » Thu Jul 23, 2015 4:44 pm

Thank you! This works like a charm.
It works without calling Draw() when TChart is placed on UserControl in design mode. However it requires force redrawing in my unit tests.

Post Reply