Pie Chart

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
rossmc
Newbie
Newbie
Posts: 57
Joined: Wed Apr 08, 2009 12:00 am

Pie Chart

Post by rossmc » Wed Sep 29, 2010 9:17 am

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

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

Re: Pie Chart

Post by Narcís » Wed Sep 29, 2010 11:35 am

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!
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

rossmc
Newbie
Newbie
Posts: 57
Joined: Wed Apr 08, 2009 12:00 am

Re: Pie Chart

Post by rossmc » Wed Sep 29, 2010 1:58 pm

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?

rossmc
Newbie
Newbie
Posts: 57
Joined: Wed Apr 08, 2009 12:00 am

Re: Pie Chart

Post by rossmc » Thu Sep 30, 2010 8:14 am

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?

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

Re: Pie Chart

Post by Narcís » Thu Sep 30, 2010 10:15 am

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

rossmc
Newbie
Newbie
Posts: 57
Joined: Wed Apr 08, 2009 12:00 am

Re: Pie Chart

Post by rossmc » Thu Sep 30, 2010 10:42 am

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?

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

Re: Pie Chart

Post by Narcís » Thu Sep 30, 2010 10:59 am

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.
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

rossmc
Newbie
Newbie
Posts: 57
Joined: Wed Apr 08, 2009 12:00 am

Re: Pie Chart

Post by rossmc » Thu Sep 30, 2010 11:22 am

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
Attachments
pie.jpg
pie.jpg (4.25 KiB) Viewed 10762 times

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

Re: Pie Chart

Post by Narcís » Thu Sep 30, 2010 2:29 pm

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!
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

rossmc
Newbie
Newbie
Posts: 57
Joined: Wed Apr 08, 2009 12:00 am

Re: Pie Chart

Post by rossmc » Fri Oct 01, 2010 8:34 am

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

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

Re: Pie Chart

Post by Narcís » Fri Oct 01, 2010 8:50 am

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

Post Reply