Page 1 of 1
CalcYPosValue returns 0
Posted: Thu Jul 23, 2015 1:59 pm
by 13049883
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.
Re: CalcYPosValue returns 0
Posted: Thu Jul 23, 2015 2:24 pm
by Christopher
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);
}
Re: CalcYPosValue returns 0
Posted: Thu Jul 23, 2015 4:44 pm
by 13049883
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.