Page 1 of 1

Drawing on a WebChart with custom axes

Posted: Mon Aug 06, 2007 8:59 am
by 9643998
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

Posted: Mon Aug 06, 2007 9:29 am
by narcis
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.

Posted: Mon Aug 06, 2007 4:08 pm
by 9643998
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?

Posted: Tue Aug 07, 2007 8:13 am
by narcis
Hi MeirS,

Try using a Bitmap call after chart's initialization as I showed you in other examples.

Posted: Tue Aug 07, 2007 11:35 am
by 9643998
Thank you Narcís,

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