Page 1 of 2
Two cursortool for standard dev of fastline
Posted: Wed Jul 07, 2010 2:09 pm
by 13056035
Hi,
I would like to make two cursor(vertical) and know in real time the value of each cursor.
So, I write this:
Code: Select all
Steema.TeeChart.WPF.Tools.CursorTool Cursor_left;
Steema.TeeChart.WPF.Tools.CursorTool Cursor_right;
Cursor_left = new Steema.TeeChart.WPF.Tools.CursorTool(tChart1.Chart);
Cursor_left.Style = Steema.TeeChart.WPF.Tools.CursorToolStyles.Vertical;
Cursor_right = new Steema.TeeChart.WPF.Tools.CursorTool(tChart1.Chart);
Cursor_right.Style = Steema.TeeChart.WPF.Tools.CursorToolStyles.Vertical;
//label1.Content = Cursor1.GetHorizAxis.ToString();
double xVal = Cursor_left.XValue;
int index = tChart1[0].XValues.IndexOf(xVal);
double yVal = tChart1[0].YValues[index];
tChart1.Header.Text = xVal.ToString() + " - " + yVal.ToString();
tChart1.Header.Visible = true;
But I can't arrive to have these values of each cursor.
And after, I want the standard deviation of all point between the two cursors.
I use visual studio 2008 with WPF and STEEMA 3.5.3188.18562
Thanks
Re: Two cursortool for standard dev of fastline
Posted: Wed Jul 07, 2010 4:43 pm
by 13056035
Hey,
I tried a new code with cursor but I had an exception as you can see on picture below :
Uploaded with
ImageShack.us
The code C# is attached of this message.
Good evening for everybody !!
Re: Two cursortool for standard dev of fastline
Posted: Fri Jul 09, 2010 8:09 am
by yeray
Hi ljoli,
You could try doing something similar to the example in the Features demo, at All Features\Welcome !\Chart styles\Standard\Line(Strip)\Interpolating line series
Re: Two cursortool for standard dev of fastline
Posted: Fri Jul 09, 2010 8:44 am
by 13056035
Thanks for your answer.
I have not see this example. I will try.
Good day
Re: Two cursortool for standard dev of fastline
Posted: Fri Jul 09, 2010 8:53 am
by 13056035
When I try the interpolating example one error arrive :
Error 1 'Steema.TeeChart.WPF.Tools.CursorTool' does not contain a definition for 'change' and no extension method 'change' accepting a first argument of type 'Steema.TeeChart.WPF.Tools.CursorTool' could be found (are you missing a using directive or an assembly reference?) C:\Users\xxx\Documents\Visual Studio 2008\Projects\training_pt\WpfApplication9\WpfApplication9\Window1.xaml.cs 150 30 WpfApplication9
Why?
Re: Two cursortool for standard dev of fastline
Posted: Fri Jul 09, 2010 8:58 am
by 13056035
I show you my code :
Code: Select all
// use cursors
this.Cursor_left = new Steema.TeeChart.WPF.Tools.CursorTool();
this.tChart1.Tools.Add(this.Cursor_left);
this.Cursor_left.Style = Steema.TeeChart.WPF.Tools.CursorToolStyles.Vertical;
//color of cursor
Cursor_left.Pen.Color = System.Windows.Media.Colors.Green;
this.Cursor_left.Pen.Color = Colors.Green;
this.Cursor_left.change += new Steema.TeeChart.WPF.Tools.CursorChangeEventHandler(this.cursorTool1_Change);
Re: Two cursortool for standard dev of fastline
Posted: Fri Jul 09, 2010 9:46 am
by yeray
Hi ljoli,
Here it is the Interpolate example translated to WPF:
Code: Select all
public Window1()
{
InitializeComponent();
InitializeChart();
}
private Steema.TeeChart.WPF.Styles.Line line1;
private Steema.TeeChart.WPF.Styles.Line line2;
private Steema.TeeChart.WPF.Styles.Line line3;
private Steema.TeeChart.WPF.Tools.CursorTool cursorTool1;
private double xval;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
line1 = new Steema.TeeChart.WPF.Styles.Line(tChart1.Chart);
line2 = new Steema.TeeChart.WPF.Styles.Line(tChart1.Chart);
line3 = new Steema.TeeChart.WPF.Styles.Line(tChart1.Chart);
line1.Pointer.Style = Steema.TeeChart.WPF.Styles.PointerStyles.Rectangle;
line2.Pointer.Style = Steema.TeeChart.WPF.Styles.PointerStyles.Circle;
line3.Pointer.Style = Steema.TeeChart.WPF.Styles.PointerStyles.Triangle;
cursorTool1 = new Steema.TeeChart.WPF.Tools.CursorTool(tChart1.Chart);
cursorTool1.FollowMouse = true;
cursorTool1.Style = Steema.TeeChart.WPF.Tools.CursorToolStyles.Vertical;
cursorTool1.Change += new Steema.TeeChart.WPF.Tools.CursorChangeEventHandler(cursorTool1_Change);
tChart1.AfterDraw += new Steema.TeeChart.WPF.PaintChartEventHandler(tChart1_AfterDraw);
foreach (Steema.TeeChart.WPF.Styles.Line s in tChart1.Series)
{
s.Pointer.Visible = true;
s.Pointer.HorizSize = 3;
s.Pointer.VertSize = 3;
s.FillSampleValues(20);
}
}
void cursorTool1_Change(object sender, Steema.TeeChart.WPF.Tools.CursorChangeEventArgs e)
{
xval = e.XValue;
tChart1.Header.Text = "";
for (int i = 0; i < tChart1.Series.Count; i++)
if (tChart1.Series[i] is Steema.TeeChart.WPF.Styles.Custom)
{
tChart1.Header.Text += tChart1.Series[i].Title + ": Y(" + e.XValue.ToString("0.00") + ")= ";
tChart1.Header.Text += InterpolateLineSeries(tChart1.Series[i] as Steema.TeeChart.WPF.Styles.Custom, e.XValue).ToString("0.00") + "\r\n";
}
}
void tChart1_AfterDraw(object sender, Steema.TeeChart.WPF.Drawing.Graphics3D g)
{
int xs = (int)tChart1.Axes.Bottom.CalcXPosValue(xval);
int ys;
g.Brush.Visible = true;
g.Brush.Solid = true;
for (int i = 0; i < tChart1.Series.Count; i++)
if (tChart1.Series[i] is Steema.TeeChart.WPF.Styles.Custom)
{
ys = (int)tChart1.Series[i].GetVertAxis.CalcYPosValue(InterpolateLineSeries(tChart1.Series[i] as Steema.TeeChart.WPF.Styles.Custom, xval));
g.Brush.Color = tChart1.Series[i].Color;
g.Ellipse(new Rect(xs - 4, ys - 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);
}
Re: Two cursortool for standard dev of fastline
Posted: Fri Jul 09, 2010 10:01 am
by 13056035
Ok Cool That is works very well
Thanks and good day Yeray
Re: Two cursortool for standard dev of fastline
Posted: Fri Jul 09, 2010 3:16 pm
by 13056035
The example of interpolating works but I can't do my objective.
I want the Y value of each cursor for know the standard deviation between the two cursors.
The problem : I can not take the value of each cursor because the function CHANGE return a VOID
like that :
Code: Select all
void cursor_right_Change(object sender, Steema.TeeChart.WPF.Tools.CursorChangeEventArgs e)
{
label1.Content = "";
for (int j = 0; j < tChart1.Series.Count; j++)
if (tChart1.Series[j] is Steema.TeeChart.WPF.Styles.Custom)
{
label1.Content = InterpolateLineSeries(tChart1.Series[j] as Steema.TeeChart.WPF.Styles.Custom, e.XValue).ToString("0.00") + "\r\n";
//string val_cursor_right
}
}
Re: Two cursortool for standard dev of fastline
Posted: Tue Jul 13, 2010 9:16 am
by yeray
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);
}
Re: Two cursortool for standard dev of fastline
Posted: Tue Jul 13, 2010 1:11 pm
by 13056035
Hi Yeray,
Thanks for your example, I was looking for a way to build this function with a global variable.
Another thing:
How to define the initial value of one cursor ??
is it like that ?
Code: Select all
// initial position
double init_value;
init_value = 200;
Cursor_left.XValue = init_value;
Thank you again for all
LJ
Re: Two cursortool for standard dev of fastline
Posted: Tue Jul 13, 2010 1:44 pm
by 13056035
ok for the initial value I see on this topic ->
http://www.teechart.net/support/viewtop ... f=4&t=9888
for init the value of cursor I do this :
Code: Select all
// initial position
Cursor_left.XValue = 100;
Cursor_left.YValue = 100;
Cursor_left.XValue = 100;
Thanks
Re: Two cursortool for standard dev of fastline
Posted: Tue Jul 13, 2010 2:37 pm
by yeray
Hi ljoli,
It was also discussed
here and there you'll find another workaround proposed.
Re: Two cursortool for standard dev of fastline
Posted: Thu Jul 15, 2010 10:48 am
by 13056035
Another problem with the "cursor.change"
Now I use a CSV file for build my fastline. And I use all code before but I had an exception
Uploaded with
ImageShack.us
I attached my code on this post.
Best regards
LJ
Re: Two cursortool for standard dev of fastline
Posted: Thu Jul 15, 2010 11:05 am
by 13056035
The exception has arrive when I want to move one cursor.
LJ