Page 1 of 1

Drawing Horizontal Line on Chart

Posted: Mon Dec 13, 2010 3:48 am
by 15657707
I have a chart whose Left axis represents a percentage from 0% to 100%. I need to draw a horizontal line across the entire chart at the 35% coordinate. I understand how to draw a horizontal line in the AfterDraw event. How do I determine where the 35% line should be located?

Re: Drawing Horizontal Line on Chart

Posted: Mon Dec 13, 2010 12:11 pm
by 10050769
Hello tcorrigan5,

I suggest do something as do in this post.

I hope will helps.

Thanks,

Re: Drawing Horizontal Line on Chart

Posted: Mon Dec 13, 2010 4:58 pm
by 15657707
No, that does not help. I have 2D chart. I need to know how to determine the vertical coordinate for the 35% mark on the left axis of the chart. I can then draw the line I need using this code in the AfterDraw event:

Code: Select all

         int pt35 = ???
         Point s = new Point(_chart.Axes.Left.Position, pt35);
         Point e = new Point(_chart.Axes.Right.Position, pt35);
         g.MoveTo(s);
         g.LineTo(e, 0);

Re: Drawing Horizontal Line on Chart

Posted: Tue Dec 14, 2010 2:14 pm
by 10050769
Hello tcorrigan5,
You can do something as next code:

Code: Select all

 public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        Steema.TeeChart.Styles.Line line1, line2;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            line2 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            line1.FillSampleValues();
            line2.FillSampleValues();
            Steema.TeeChart.Axis axis = new Steema.TeeChart.Axis(tChart1.Chart);
            tChart1.Axes.Custom.Add(axis);
                    
            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);

        }
        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            g.Pen.Color = Color.Red;
            int value =tChart1.Axes.Left.CalcYPosValue(tChart1.Axes.Left.IAxisSize * 35 / 100);
            g.Line(tChart1.Axes.Bottom.IStartPos, value, tChart1.Axes.Bottom.IEndPos, value);
        }
Could you tell us if previous code works as you want?

I hope will helps.

Thanks,

Re: Drawing Horizontal Line on Chart

Posted: Tue Dec 14, 2010 5:02 pm
by 15657707
No, your code doesn't work but this does:

Code: Select all

         int value = _chart.Axes.Left.CalcYPosValue(0.35);
         g.Line(_chart.Axes.Bottom.IStartPos, value, _chart.Axes.Bottom.IEndPos, value);
i.e., you don't need the IAxisSize factor in the calculation.

Re: Drawing Horizontal Line on Chart

Posted: Thu Dec 16, 2010 1:17 pm
by 10050769
Hello tcorrigan5,

You need IAxisSize value for calculate value that corresponds 35% of axes size, because you have to sum it to StartPosition of Axes for get the correct position of line that you want draw. You can do it as in next code:

Code: Select all

 private  Steema.TeeChart.Styles.Line line1,line2;
     private void InitializeChart()
     {
            tChart1.Aspect.View3D = false;
            line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            line2 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            line1.FillSampleValues();
                   
            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            g.Pen.Color = Color.Red;
            int pos = tChart1.Axes.Left.IStartPos + (tChart1.Axes.Left.IAxisSize * 35) / 100;
            g.Line(tChart1.Axes.Bottom.IStartPos, pos, tChart1.Axes.Bottom.IEndPos, pos);
        }
    }
I hope will helps.

Thanks