Hi ljoli,
But you can use global variables, isn't it?
I've simplified the example above. Now you can see only a line series and two cursor tools. And I've added a calc method where you could calculate what you want, for example, the interpolation positions, as I do.
Code: Select all
public Window1()
{
InitializeComponent();
InitializeChart();
}
private Steema.TeeChart.WPF.Styles.Line line1;
private Steema.TeeChart.WPF.Tools.CursorTool Cursor_left;
private Steema.TeeChart.WPF.Tools.CursorTool Cursor_right;
private double val_cursor_left, val_cursor_right;
int x_left, x_right, y_left, y_right;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
line1 = new Steema.TeeChart.WPF.Styles.Line(tChart1.Chart);
line1.Pointer.Style = Steema.TeeChart.WPF.Styles.PointerStyles.Rectangle;
line1.Pointer.Visible = true;
line1.Pointer.HorizSize = 3;
line1.Pointer.VertSize = 3;
line1.FillSampleValues(20);
Cursor_left = new Steema.TeeChart.WPF.Tools.CursorTool(tChart1.Chart);
Cursor_left.Style = Steema.TeeChart.WPF.Tools.CursorToolStyles.Vertical;
Cursor_left.Change += new Steema.TeeChart.WPF.Tools.CursorChangeEventHandler(Cursor_left_Change);
Cursor_right = new Steema.TeeChart.WPF.Tools.CursorTool(tChart1.Chart);
Cursor_right.Style = Steema.TeeChart.WPF.Tools.CursorToolStyles.Vertical;
Cursor_right.Change += new Steema.TeeChart.WPF.Tools.CursorChangeEventHandler(Cursor_right_Change);
tChart1.AfterDraw += new Steema.TeeChart.WPF.PaintChartEventHandler(tChart1_AfterDraw);
}
void Cursor_left_Change(object sender, Steema.TeeChart.WPF.Tools.CursorChangeEventArgs e)
{
val_cursor_left = e.XValue;
recalc();
}
void Cursor_right_Change(object sender, Steema.TeeChart.WPF.Tools.CursorChangeEventArgs e)
{
val_cursor_right = e.XValue;
recalc();
}
private void recalc()
{
x_left = (int)tChart1.Axes.Bottom.CalcXPosValue(val_cursor_left);
x_right = (int)tChart1.Axes.Bottom.CalcXPosValue(val_cursor_right);
y_left = (int)tChart1[0].GetVertAxis.CalcYPosValue(InterpolateLineSeries(tChart1[0] as Steema.TeeChart.WPF.Styles.Custom, val_cursor_left));
y_right = (int)tChart1[0].GetVertAxis.CalcYPosValue(InterpolateLineSeries(tChart1[0] as Steema.TeeChart.WPF.Styles.Custom, val_cursor_right));
}
void tChart1_AfterDraw(object sender, Steema.TeeChart.WPF.Drawing.Graphics3D g)
{
g.Brush.Visible = true;
g.Brush.Solid = true;
g.Brush.Color = tChart1[0].Color;
g.Ellipse(new Rect(x_left - 4, y_left - 4, 8, 8));
g.Ellipse(new Rect(x_right - 4, y_right - 4, 8, 8));
}
private double InterpolateLineSeries(Steema.TeeChart.WPF.Styles.Custom series, int firstindex, int lastindex, double xvalue)
{
int index;
for (index = firstindex; index <= lastindex; index++)
{
if (index == -1 || series.XValues.Value[index] > xvalue) break;
}
// safeguard
if (index < 1) index = 1;
else if (index >= series.Count) index = series.Count - 1;
// y=(y2-y1)/(x2-x1)*(x-x1)+y1
double dx = series.XValues[index] - series.XValues[index - 1];
double dy = series.YValues[index] - series.YValues[index - 1];
if (dx != 0.0) return dy * (xvalue - series.XValues[index - 1]) / dx + series.YValues[index - 1];
else return 0.0;
}
private double InterpolateLineSeries(Steema.TeeChart.WPF.Styles.Custom series, double xvalue)
{
return InterpolateLineSeries(series, series.FirstVisibleIndex, series.LastVisibleIndex, xvalue);
}