Page 1 of 1

DrawLine & axis and programatically redrawing.

Posted: Thu Jul 08, 2010 6:05 am
by 8751509
Greetings,

I am trying to implement a trend line for use with a Stock Data Chart.

Code: Select all

        private void popMenuTrendLine_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DrawLine drawLine = new DrawLine();
            drawLine.NewLine += new DrawLineEventHandler(drawLine_NewLine);
            StockChart.Aspect.View3D = false;
            drawLine.Style = DrawLineStyle.Line;
            drawLine.Pen.Color = Color.Blue;
            drawLine.Pen.Width = 2;
            drawLine.Pen.Transparency = 50;
            
            StockChart.Tools.Add(drawLine);
        }

        void drawLine_NewLine(DrawLine sender)
        {
            DrawLine drawLn = (DrawLine)sender;

            Debug.Print("X0:" + drawLn.Selected.StartPos.X.ToString() +
                        " Y0:" + drawLn.Selected.StartPos.Y.ToString());
            Debug.Print("X1:" + drawLn.Selected.EndPos.X.ToString() +
                        " Y1:" + drawLn.Selected.EndPos.Y.ToString());
            Debug.Print("--------------------------------------------------");
            
            //SaveOutTrendLineVals(X0,Y0,X1,Y1);
            drawLn.NewLine -= new DrawLineEventHandler(drawLine_NewLine);
            drawLn.Active = false;
            
            Debug.Print(StockChart.Tools.Count.ToString());
            Debug.Print("--------------------------------------------------");
        }
1. I cant seem to use this line with a right Axis ... the Y value is always 0 .. how do I associate a drawLine with the right axis (if I turn on th LEFT axis it works fine but I need a Right axis)

2. I wish to draw a single line then return to other user tasks ... if I dont have the line "drawLn.Active = false;" I am forever stuck drawing lines on the screen ... if I DO have that line .. all my lines disapear from the chart .. (even though StockChart.Tools.Count shows they are in this collection.)

3. How can I programatically redraw these DrawLines .. as I need to save X0,y0,x1,y1 co-ords to a file and redraw the lines at a later time.

Regards Phil.

Re: DrawLine & axis and programatically redrawing.

Posted: Fri Jul 09, 2010 8:51 am
by yeray
Hi Phil,
Snarkle wrote:1. I cant seem to use this line with a right Axis ... the Y value is always 0 .. how do I associate a drawLine with the right axis (if I turn on th LEFT axis it works fine but I need a Right axis)
Right. I could reproduce it with the code below. I've added it to the defect list to be fixed asap (TF02015019).

Code: Select all

        private void InitializeChart()
        {
            Steema.TeeChart.Styles.Points points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            points1.FillSampleValues();

            Steema.TeeChart.Tools.DrawLine drawline1 = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);

            points1.VertAxis = Steema.TeeChart.Styles.VerticalAxis.Right;
        }
Snarkle wrote:2. I wish to draw a single line then return to other user tasks ... if I dont have the line "drawLn.Active = false;" I am forever stuck drawing lines on the screen ... if I DO have that line .. all my lines disapear from the chart .. (even though StockChart.Tools.Count shows they are in this collection.)
This is by design. The DrawLine tool is a tool that allows you to draw multiple lines. If you disable the tool, all its lines are hidden. If you want "independent" lines, you need to create multiple DrawLine tools.
Snarkle wrote:3. How can I programatically redraw these DrawLines .. as I need to save X0,y0,x1,y1 co-ords to a file and redraw the lines at a later time.
Here you have an example of how you could add a line to a DrawLine tool at runtime:

Code: Select all

        Steema.TeeChart.Styles.Points points1;
        Steema.TeeChart.Tools.DrawLine drawline1;
        Steema.TeeChart.Tools.DrawLineItem I;
        private void InitializeChart()
        {
            points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            points1.FillSampleValues();

            drawline1 = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);

            I = new Steema.TeeChart.Tools.DrawLineItem(drawline1);
            double tmp = points1.YValues.Range / 5.0;
            I.StartPos = new Steema.TeeChart.Drawing.PointDouble(5, points1.YValues.Maximum - tmp);
            I.EndPos = new Steema.TeeChart.Drawing.PointDouble(15, points1.YValues.Minimum + tmp);
        }

Re: DrawLine & axis and programatically redrawing.

Posted: Tue Jul 13, 2010 12:05 am
by 8751509
AH .. I see now .. thanks again ... and I worked around the right axis problem by swapping the Left axis over to the right.

Re: DrawLine & axis and programatically redrawing.

Posted: Tue Jul 27, 2010 1:59 pm
by yeray
Hi Phil,
Yeray wrote:Right. I could reproduce it with the code below. I've added it to the defect list to be fixed asap (TF02015019).

Code: Select all

        private void InitializeChart()
        {
            Steema.TeeChart.Styles.Points points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            points1.FillSampleValues();

            Steema.TeeChart.Tools.DrawLine drawline1 = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);

            points1.VertAxis = Steema.TeeChart.Styles.VerticalAxis.Right;
        }
After investigating this a little bit deeper, we realized that this is not a bug. The issue is that the DrawLineTool's Series property needs to be set:

Code: Select all

drawline1.Series = points1; //set Series