Pie chart - other slice

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
UserLS
Advanced
Posts: 247
Joined: Wed May 23, 2007 12:00 am

Pie chart - other slice

Post by UserLS » Tue Nov 17, 2009 6:53 pm

This is another problem with logic embedded into paint events. I have a pie chart and I am using OtherSlice feature. The chart is saved into a file and I am reading this file and creating the chart in memory. But until the chart is actually drawn on the screen (which I am not even planning to do) the OtherSlice is not created and the pie even has no idea which slices will fall into it! That makes it impossible for me to create the chart I need. Also, when I need to save my chart, I need to turn off the OtherSlice and I am running into the same problem again - without actually drawing the chart it still thinks that some of the slices belong to OtherSlice (even though it's style is None by then!)

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

Re: Pie chart - other slice

Post by Sandra » Wed Nov 18, 2009 11:10 am

Hello UserLs,

I couldn't reproduce your problem using following code with version3 of TeeChart .Net. Please, check previous project works as you want.

Code: Select all

    public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private Steema.TeeChart.Styles.Pie pie1;
        private Steema.TeeChart.TChart tChart2;
        private void InitializeChart()
        {
            tChart2 = new Steema.TeeChart.TChart();
            pie1 = new Steema.TeeChart.Styles.Pie(tChart2.Chart);
            pie1.FillSampleValues();
            pie1.OtherSlice.Style = Steema.TeeChart.Styles.PieOtherStyles.BelowPercent;
            pie1.OtherSlice.Value = 10;
            pie1.OtherSlice.Legend.Visible = true;
            pie1.OtherSlice.Legend.Left = tChart2.Legend.Left;
            pie1.OtherSlice.Legend.Top = tChart2.Legend.Bottom;
            tChart2.Export.Template.Save("c:\\tChart.ten");         
        }

        private void button1_Click(object sender, EventArgs e)
        {
            tChart1.Import.Template.Load("c:\\tChart.ten");
        }
If previous project doesn’t work as you want, I suggest modifying this simple project, because we can reproduce the issue here.


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

UserLS
Advanced
Posts: 247
Joined: Wed May 23, 2007 12:00 am

Re: Pie chart - other slice

Post by UserLS » Wed Nov 18, 2009 6:36 pm

Here is the code, you can run to see the problem:

Code: Select all

            var chart = new TChart();
            var pie = new Pie(chart.Chart);
            pie.FillSampleValues();
            pie.OtherSlice.Style = PieOtherStyles.BelowPercent;
            pie.OtherSlice.Value = 30;

            var allSlices = "";
            var visibleSlices = "";
            for (var idx = 0; idx < pie.PieValues.Count; idx++)
            {
                allSlices = allSlices + "\r\n" + pie.PieValues[idx];
                if (!pie.BelongsToOtherSlice(idx))
                    visibleSlices = visibleSlices + "\r\n" + pie.PieValues[idx];
            }

            MessageBox.Show(String.Format("The two lists should be different:\r\n{0}\r\n\r\n{1}",
                allSlices, visibleSlices));

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

Re: Pie chart - other slice

Post by Sandra » Thu Nov 19, 2009 10:08 am

Hello UserLs,

I could reproduce your issue with version 3 of TeeChart .Net. I have been investigatin and I found that BelongToOtherSlice need to draw Chart(chart.Draw()),otherwise you will not run the internal method DoBeforeDrawChart() and BelongToOtherSlice will not be updated. I recommend using workaround chart.Draw(), as do in next code:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private Steema.TeeChart.Styles.Pie pie;
        private Steema.TeeChart.TChart chart;
        private void InitializeChart()
        {
            var chart = new Steema.TeeChart.TChart();
            var pie = new Steema.TeeChart.Styles.Pie(chart.Chart);
            pie.Add(20);
            pie.Add(15);
            pie.Add(12);
            pie.Add(18);
            pie.Add(5);
            pie.Add(8);
            pie.Add(7);
            pie.Add(15);
            pie.OtherSlice.Style = Steema.TeeChart.Styles.PieOtherStyles.BelowPercent;
            pie.OtherSlice.Value = 10;
            chart.Draw();
            var allSlices = "";
            var visibleSlices = "";
            for (var idx = 0; idx < pie.Count; idx++)
            {
                allSlices = allSlices + "\r\n" + pie.PieValues[idx];
                if (!pie.BelongsToOtherSlice(idx))
                    visibleSlices = visibleSlices + "\r\n" + pie.PieValues[idx];
            }

            MessageBox.Show(String.Format("The two lists should be different:\r\n{0}\r\n\r\n{1}",
                allSlices, visibleSlices));
}
You can see in the code above that is painted internally, because project works fine.

On the other hand, I have added your enhancement request to the wish-list to be considered for inclusion in future.

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

UserLS
Advanced
Posts: 247
Joined: Wed May 23, 2007 12:00 am

Re: Pie chart - other slice

Post by UserLS » Thu Nov 19, 2009 2:34 pm

The problem with calling Draw() event is that under some versions of Windows it does nothing unless you are actually showing a form on your screen (not even outside of the screen boundaries), which is not an option for me.

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

Re: Pie chart - other slice

Post by Sandra » Mon Nov 23, 2009 10:49 am

Hello UserLs,
The problem with calling Draw() event is that under some versions of Windows it does nothing unless you are actually showing a form on your screen (not even outside of the screen boundaries), which is not an option for me.
Please could you tell us under what versions of Windows you are experiencing the problems. We are not aware of the limitations you describe and would like to be able to reproduce them here to help find a solution.



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