How to read y coordinates of error series in teechart? I want Upper and lower coordinates of y axis when cursor moves on it.
You need to use a TeeChart mouse event (eg.: OnMouseMove) and series' Clicked method to know which point is under the mouse and retrieve corresponding values as in this example:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
tChart1.Series.Add(new Steema.TeeChart.Styles.Error()).FillSampleValues();
tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);
}
void tChart1_MouseMove(object sender, MouseEventArgs e)
{
Steema.TeeChart.Styles.Error error1 = (Steema.TeeChart.Styles.Error)tChart1[0];
int index = error1.Clicked(e.X, e.Y);
string tmp = "";
if (index != -1)
{
double y = error1.YValues[index];
double error = error1.ErrorValues[index];
double top = y + error;
double bottom = y - error;
tmp = top.ToString("#.##") + " - " + bottom.ToString("#.##");
}
else
{
tmp = "";
}
this.Text = tmp;
}
}
If you use a CursorTool there are e.XValue and e.YValue arguments which give you the axes values of the CursorTool and e.x and e.y which are the equivalent of MouseMove e.X and e.Y arguments so you can do the same as with that event, a simple example:
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
tChart1.Series.Add(new Steema.TeeChart.Styles.Error()).FillSampleValues();
//tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);
Steema.TeeChart.Tools.CursorTool cursor1 = new Steema.TeeChart.Tools.CursorTool(tChart1.Chart);
cursor1.Series = tChart1[0];
cursor1.FollowMouse = true;
cursor1.Change += new Steema.TeeChart.Tools.CursorChangeEventHandler(cursor1_Change);
}
void cursor1_Change(object sender, Steema.TeeChart.Tools.CursorChangeEventArgs e)
{
Steema.TeeChart.Styles.Error error1 = (Steema.TeeChart.Styles.Error)tChart1[0];
int index = error1.Clicked(e.x, e.y);
string tmp = "";
if (index != -1)
{
double y = error1.YValues[index];
double error = error1.ErrorValues[index];
double top = y + error;
double bottom = y - error;
tmp = "Error top: " + top.ToString("#.##") +
" Error bottom: " + bottom.ToString("#.##") +
" Cursor pos.: " + e.XValue.ToString("#.##") + "/" + e.YValue.ToString("#.##");
}
else
{
tmp = "";
}
this.Text = tmp;
}