Two cursortool for standard dev of fastline

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Two cursortool for standard dev of fastline

Post by Yeray » Thu Jul 15, 2010 4:06 pm

Hi ljoli,

You are using FastLine series, that doesn't inherit from Custom. Changing the InterpolateLineSeries declaration to take a BaseLine instead of a Custom "series" as argument, and also changing the cast when calling the InterpolateLineSeries funtion, it works also for FastLineSeries:

Code: Select all

        public Window1()
        {
            InitializeComponent();
            InitializeChart();
        }

        private Steema.TeeChart.WPF.Styles.FastLine fastline1;
        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;

            fastline1 = new Steema.TeeChart.WPF.Styles.FastLine(tChart1.Chart);
            fastline1.FillSampleValues(300);

            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_left.Pen.Color = System.Windows.Media.Colors.Blue;
            double init_cursor_left = 100;
            Cursor_left.XValue = init_cursor_left;
            Cursor_left.YValue = init_cursor_left;
            Cursor_left.XValue = init_cursor_left;
            

            Cursor_right = new Steema.TeeChart.WPF.Tools.CursorTool(tChart1.Chart);
            Cursor_right.Style = Steema.TeeChart.WPF.Tools.CursorToolStyles.Vertical;
            Cursor_right.Pen.Color = System.Windows.Media.Colors.Orange;
            Cursor_right.Change += new Steema.TeeChart.WPF.Tools.CursorChangeEventHandler(Cursor_right_Change);
            double init_cursor_right = 200;
            Cursor_right.XValue = init_cursor_right;
            Cursor_right.YValue = init_cursor_right;
            Cursor_right.XValue = init_cursor_right;
            

            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.BaseLine, val_cursor_left));
            y_right = (int)tChart1[0].GetVertAxis.CalcYPosValue(InterpolateLineSeries(tChart1[0] as Steema.TeeChart.WPF.Styles.BaseLine, 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 = Cursor_left.Pen.Color;
            g.Ellipse(new Rect(x_left - 4, y_left - 4, 8, 8));
            g.Brush.Color = Cursor_right.Pen.Color;
            g.Ellipse(new Rect(x_right - 4, y_right - 4, 8, 8));
        }

        private double InterpolateLineSeries(Steema.TeeChart.WPF.Styles.BaseLine 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.BaseLine series, double xvalue)
        {
            return InterpolateLineSeries(series, series.FirstVisibleIndex, series.LastVisibleIndex, xvalue);
        }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

ljoli
Newbie
Newbie
Posts: 24
Joined: Wed Apr 28, 2010 12:00 am
Location: Paris, FRANCE

Re: Two cursortool for standard dev of fastline

Post by ljoli » Fri Jul 16, 2010 12:25 pm

Hi,

That is works on my project. The two cursors give me all data what I want. :wink:


Thanks lot Yeray and nice day

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Two cursortool for standard dev of fastline

Post by Yeray » Fri Jul 16, 2010 1:45 pm

Hi ljoli,

You are welcome!
Have a nice day you too.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply