Drawing Horizontal Line on Chart

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
tcorrigan5
Newbie
Newbie
Posts: 11
Joined: Tue Nov 02, 2010 12:00 am

Drawing Horizontal Line on Chart

Post by tcorrigan5 » Mon Dec 13, 2010 3:48 am

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?

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Drawing Horizontal Line on Chart

Post by Sandra » Mon Dec 13, 2010 12:11 pm

Hello tcorrigan5,

I suggest do something as do in this post.

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

tcorrigan5
Newbie
Newbie
Posts: 11
Joined: Tue Nov 02, 2010 12:00 am

Re: Drawing Horizontal Line on Chart

Post by tcorrigan5 » Mon Dec 13, 2010 4:58 pm

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);

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Drawing Horizontal Line on Chart

Post by Sandra » Tue Dec 14, 2010 2:14 pm

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,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

tcorrigan5
Newbie
Newbie
Posts: 11
Joined: Tue Nov 02, 2010 12:00 am

Re: Drawing Horizontal Line on Chart

Post by tcorrigan5 » Tue Dec 14, 2010 5:02 pm

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.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Drawing Horizontal Line on Chart

Post by Sandra » Thu Dec 16, 2010 1:17 pm

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
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply