Page 1 of 1

Pie Chart

Posted: Wed Sep 29, 2010 9:17 am
by 13052926
I need to create a pie chart with fairly complex requirements.

Basically I want to divide the pie into four equal quadrants. Each quadrant may then have between 2 to 7 slices added to it. I need to control to a high degree the specific slices within each quadrant. Can I do this with the pie chart?

Thanks

Re: Pie Chart

Posted: Wed Sep 29, 2010 11:35 am
by narcis
Hi rossmc,

Yes, I think so. You can use a combination of whats shown in the All Features\Welcome!\Chart Styles\Standard\Multiple Pies example and the All Features\Welcome!\Chart Styles\Standard\Semi-pie example in the features demo available at TeeChart's program group. I'd use 4 pie series located as in the multiple pies example and set their angle as in the semi-pie example.

Hope this helps!

Re: Pie Chart

Posted: Wed Sep 29, 2010 1:58 pm
by 13052926
Thanks Narcis

After a closer look at the spec I realised that although the slices per quadrant may vary between 2 and 7, for each individual chart instance every quadrant will have the same number of slices. This simplifies my task considerably as I can now do everything on a single chart - much easier!

What I would like to do now however is label each slice along the circumference of the pie. In other words, outside the enclosing circle of the pie, at the end of each slice I want to label the slice with a three character code. The labels need to go around the pie-the angle of the labels would need to change depending on their location along the circumference. Any ideas on this. Sorry to be a pain but this is a rush job and I have no experience using the pie series. Many thanks!

Sorry, something else. If I want to manually draw 'spokes' within a slice - a line originating in the exact centre of the pie and extending towards the circumference for a specified length. I have added a drawline tool with the idea of simply adding lines to it for each 'spoke'. If this will work, what are the coordinates in a pie chart? Unless I should be doing this some other way?

Re: Pie Chart

Posted: Thu Sep 30, 2010 8:14 am
by 13052926
Hi again

Made a bit more progress on this task. The only thing I'm missing now is the ability to draw the text labels as previously indicated. I thought of using the .RotateLabel?

My real problem is I do not know how to obtain the actual dimensions of the pie? Since I'm drawing directly on the canvas I'm working with x and y coordinates in the canvas rectangle. It would help however if I knew how to obtain the radius of the pie?

Re: Pie Chart

Posted: Thu Sep 30, 2010 10:15 am
by narcis
Hi rossmc,
Made a bit more progress on this task. The only thing I'm missing now is the ability to draw the text labels as previously indicated. I thought of using the .RotateLabel?
Standard series marks don't do the job for you? You can easily fill them using the label parameter in the add method when populating them or use series' Labels ValueList. I think it would be much easier doing this with series marks with a little bit customization if necessary.
My real problem is I do not know how to obtain the actual dimensions of the pie? Since I'm drawing directly on the canvas I'm working with x and y coordinates in the canvas rectangle. It would help however if I knew how to obtain the radius of the pie?
You can use CircleXCenter and CircleYCenter, for example:

Code: Select all

            Point center = new Point(pie1.CircleXCenter, pie1.CircleYCenter);

Re: Pie Chart

Posted: Thu Sep 30, 2010 10:42 am
by 13052926
Re the labels, the problem is the spec calls for the labels to align along the circumference of the chart. Each label is just three characters long. No matter where along the circumference the bottom of the text must always run along the edge of the circumference. Can I do something like this with series marks?

Re: Pie Chart

Posted: Thu Sep 30, 2010 10:59 am
by narcis
Hi rossmc,

Yes, I think so even I'm not 100% sure about what you are trying to do exactly :). You may need to set marks ArrowLength to zero. If this doesn't help could you please attach an image of what you are trying to do?

Thanks in advance.

Re: Pie Chart

Posted: Thu Sep 30, 2010 11:22 am
by 13052926
Hi Narcis

Uploaded a very quick paint drawing. You will see how the labels go around the circumference. Of course there will also be labels at intermediate points along the circumference but I couldn't get paint to rotate text by 45 degrees :)

Thanks

Re: Pie Chart

Posted: Thu Sep 30, 2010 2:29 pm
by narcis
Hi rossmc,

Ok, you can rotate standard marks but you can't have a different angle for each mark so custom text drawing is the way to go, for example:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        private Steema.TeeChart.Styles.Pie pie1;

        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.Legend.Visible = false;

            pie1 = new Steema.TeeChart.Styles.Pie(tChart1.Chart);
            pie1.FillSampleValues();
            pie1.Circled = true;
            pie1.Marks.Visible = false;

            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            for (int i = 0; i < pie1.Count; i++)
            {
                double pieAngle = pie1.Angles[i].MidAngle;
                int x, y;

                pie1.AngleToPos(pieAngle, pie1.XRadius + 20, pie1.YRadius + 20, out x, out y);
                g.RotateLabel(x, y, pie1.Labels[i], Steema.TeeChart.Utils.Rad2Deg(pieAngle) - 90);
            }
        }
Hope this helps!

Re: Pie Chart

Posted: Fri Oct 01, 2010 8:34 am
by 13052926
Wow, great answer! Exactly what I was trying to do. The only thing here is I do not have the .Rad2Deg method in my control. I am using version 3.5

Re: Pie Chart

Posted: Fri Oct 01, 2010 8:50 am
by narcis
Hi rossmc,
Wow, great answer! Exactly what I was trying to do.
Excellent! I'm glad to hear that's what you were looking for.
The only thing here is I do not have the .Rad2Deg method in my control. I am using version 3.5
I used TeeChart 2010 aka v4 for this example. Actually this method is pretty straightforward:

Code: Select all

    /// <summary>
    ///Returns a degree value from a radian value.
    /// </summary>
    static public double Rad2Deg(double radian)
    {
      return radian * (180 / Math.PI);
    }