Drawing on a WebChart with custom axes

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
MeirS
Newbie
Newbie
Posts: 14
Joined: Thu Jan 25, 2007 12:00 am

Drawing on a WebChart with custom axes

Post by MeirS » Mon Aug 06, 2007 8:59 am

Hi,

I have WebChart with 6 series each one on a custom axis

1. For every axis I want to draw it's zero line that should start from the left
(left axis of the graph) and go to the right (right axis of the graph)

2. For every axis I want to show on the right (right axis of the graph)
the minimum and maximum axis values with ticks for the minimum and the maximum
I also need to add text between the minimum and maximum values
i.e. for the voltage series V1 I want 473 for maximum, -473 for minimum and "kVolts" for the text

I tried to add the lines, ticks and the text on the "WebChart1_BeforeDraw" event

Code: Select all

           for (int i = 0; i < WebChart1.Chart.Series.Count; i++)
            {
                    if (WebChart1.Chart.Series[i].CalcYPosValue(0) > WebChart1.Chart.Axes.Top.Position && WebChart1.Chart.Series[i].CalcYPosValue(0) < WebChart1.Chart.Axes.Bottom.Position)
                    {

                            Axis customAxis = WebChart1.Chart.Series[i].CustomVertAxis;
                            g.Pen.Color = Color.Black;

			    //draw axis	for series
                            g.MoveTo(WebChart1.Chart.Axes.Left.Position, WebChart1.Chart.Series[i].CalcYPosValue(0));
                            g.LineTo(WebChart1.Chart.Axes.Right.Position, WebChart1.Chart.Series[i].CalcYPosValue(0));

			    //draw a tick and the maximum value for axis
                            int yPos = WebChart1.Chart.Series[i].CalcYPosValue(customAxis.Maximum) + 7;
                            g.MoveTo(WebChart1.Chart.Axes.Right.Position, yPos);
                            g.LineTo(WebChart1.Chart.Axes.Right.Position + 3, yPos);
                            g.TextOut(WebChart1.Chart.Axes.Right.Position + 10, yPos - 8, Convert.ToString(customAxis.Maximum));

                            //draw a tick and the minimum value for axis
                            yPos = WebChart1.Chart.Series[i].CalcYPosValue(customAxis.Minimum) - 5;
                            g.MoveTo(WebChart1.Chart.Axes.Right.Position, yPos);
                            g.LineTo(WebChart1.Chart.Axes.Right.Position + 3, yPos);
                            g.TextOut(WebChart1.Chart.Axes.Right.Position + 7, yPos - 8, Convert.ToString(customAxis.Minimum));
                   }

          }
This code does not work because all the following values are 0
WebChart1.Chart.Axes.Left.Position
WebChart1.Chart.Axes.Right.Position
WebChart1.Chart.Axes.Top.Position (which I also need do more custom drawing on the chart)
How do I get the positions of these axes on the screen?

Please help

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Aug 06, 2007 9:29 am

Hi MeirS,

This is because in the event you are using the chart hasn't been drawn and thus does properties don't have valid values or haven't been initialized. You should implement this code in the OnAfterDraw event.

Regarding drawing such lines, you could try using ColorBand tool and set start and end position being the same. For drawing text to the labels you could use the OnGetNextAxisLabel event.
Best Regards,
Narcís Calvet / 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

MeirS
Newbie
Newbie
Posts: 14
Joined: Thu Jan 25, 2007 12:00 am

Post by MeirS » Mon Aug 06, 2007 4:08 pm

Hi Narcís,

I implemented the code in the OnAfterDraw event, and still
WebChart1.Chart.Axes.Left.Position
WebChart1.Chart.Axes.Right.Position
WebChart1.Chart.Axes.Top.Position
are all 0
How to make teechart fill them for me?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Aug 07, 2007 8:13 am

Hi MeirS,

Try using a Bitmap call after chart's initialization as I showed you in other examples.
Best Regards,
Narcís Calvet / 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

MeirS
Newbie
Newbie
Posts: 14
Joined: Thu Jan 25, 2007 12:00 am

Post by MeirS » Tue Aug 07, 2007 11:35 am

Thank you Narcís,

After the call to Bitmap() I have the positions I need in
WebChart1.Chart.ChartRect

Post Reply