Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Fri Jun 27, 2014 3:49 pm

I am figuring how to embed a pie chart using the following code (Using the free edition of Spire.Presentation):

Code: Select all
IChart piechart = presentation.Slides[1].Shapes.AppendChart(ChartType.Pie3D, rect);
piechart.ChartTitle.TextProperties.Text = "Shares of Preference";
piechart.ChartTitle.TextProperties.IsCentered = true;
piechart.ChartTitle.Height = 30;
piechart.HasTitle = true;

String[] products = new String[] { "Product 1", "Product 2", "None" };
Int32[] shares = new Int32[] { 50, 30, 20 };

piechart.ChartData[0, 0].Text = "Product";
piechart.ChartData[0, 1].Text = "Share";
for (Int32 i = 0; i < products.Length; ++i)
{
   // the rows must start at 1
   piechart.ChartData[i + 1, 0].Value = products[i];
   piechart.ChartData[i + 1, 1].Value = shares[i];
}


When the document is generated, the data include another row which I didn't have:
Code: Select all
Product   Share
Product 1    50
Product 2    30
None         20
4th Qtr      1.2

Is this left over from some debugging code, or how did this get into my chart?

sparticus1701
 
Posts: 5
Joined: Fri Jun 27, 2014 1:18 pm

Mon Jun 30, 2014 8:28 am

Hello,

Sorry for the delay response for the weekends here. Thanks for your inquiry.
I have reproduced your issue and posted it to our dev team, sorry for the inconvenience.
We will inform you when it is resolved.

Welcome to write to us again for further problems.

Best wishes,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Jul 01, 2014 2:50 am

Hello,

We provide you the below solution to generate the correct piechart.
We will resolve the incorrect data source issue in next version. When the new version is released, we will inform you.

Code: Select all
 Presentation presentation = new Presentation();
            RectangleF rect = new RectangleF(0, 50, 200, 50);
            IChart piechart = presentation.Slides[0].Shapes.AppendChart(ChartType.Pie3D, rect);
            piechart.ChartTitle.TextProperties.Text = "Shares of Preference";
            piechart.ChartTitle.TextProperties.IsCentered = true;
            piechart.ChartTitle.Height = 30;
            piechart.HasTitle = true;

            String[] products = new String[] { "Product 1", "Product 2", "None" };
            Int32[] shares = new Int32[] { 50, 30, 20 };

            piechart.ChartData[0, 0].Text = "Product";
            piechart.ChartData[0, 1].Text = "Share";
            for (Int32 i = 0; i < products.Length; ++i)
            {
                // the rows must start at 1
                piechart.ChartData[i + 1, 0].Value = products[i];
                piechart.ChartData[i + 1, 1].Value = shares[i];
            }
            piechart.Series.Clear();
            piechart.Categories.Clear();
            piechart.Categories.CategoryLabels = piechart.ChartData["A2", "A4"];
            piechart.Series.SeriesLabel = piechart.ChartData["B1", "B1"];
            piechart.Series[0].Values = piechart.ChartData["B2","B4"];

            presentation.SaveToFile("Editing.pptx", FileFormat.Pptx2007);
            System.Diagnostics.Process.Start("Editing.pptx");


Best wishes,
Amy
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Fri Jul 11, 2014 8:41 am

Hello,

Thanks for your waiting.
The issue has been resolved. Welcome to download Free Spire.Presentation Hotfix for .NET Version:2.0.17 (http://www.e-iceblue.com/Download/downl ... t-now.html)and test the following code.
Code: Select all
string outputFile = @"..\..\..\..\TestResult.pptx";
Presentation presentation = new Presentation();
RectangleF rect = new RectangleF(0, 50, 200, 50);
IChart piechart = presentation.Slides[0].Shapes.AppendChart(ChartType.Pie3D, rect, false);
piechart.ChartTitle.TextProperties.Text = "Shares of Preference";
piechart.ChartTitle.TextProperties.IsCentered = true;
piechart.ChartTitle.Height = 30;
piechart.HasTitle = true;
String[] products = new String[] { "Product 1", "Product 2", "None" };
Int32[] shares = new Int32[] { 50, 30, 20 };
piechart.ChartData[0, 0].Text = "Product";
piechart.ChartData[0, 1].Text = "Share";
for (Int32 i = 0; i < products.Length; ++i)
{
   // the rows must start at 1
   piechart.ChartData[i + 1, 0].Value = products[i]; piechart.ChartData[i + 1, 1].Value = shares[i];
}
piechart.Categories.CategoryLabels = piechart.ChartData["A2", "A4"];
piechart.Series.SeriesLabel = piechart.ChartData["B1", "B1"];
piechart.Series[0].Values = piechart.ChartData["B2", "B4"];

   presentation.SaveToFile(outputFile, FileFormat.Pptx2010);



Best wishes,
Amy
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed Jul 16, 2014 9:22 am

Hello,

Have you tested Free Spire.Presentation Hotfix for .NET Version:2.0.17? How did it work?
Thanks for your feedback.

Best Regards,
Amy
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed Jul 16, 2014 1:47 pm

I apologize for not looking at it sooner -- I've been busy and the feature we'd like to use this component for is not scheduled for another few months.

I pulled up the Chart-VS2012 demo, changed the references to the new dlls, and inserted the code found earlier in the thread. It works, but if I comment out the lines

Code: Select all
piechart.Series.Clear();
piechart.Categories.Clear();
piechart.Categories.CategoryLabels = piechart.ChartData["A2", "A4"];
piechart.Series.SeriesLabel = piechart.ChartData["B1", "B1"];
piechart.Series[0].Values = piechart.ChartData["B2", "B4"];


then I get the same behavior as before. If I also comment out

Code: Select all
piechart.ChartData[0, 0].Text = "Product";
piechart.ChartData[0, 1].Text = "Share";
for (Int32 i = 0; i < products.Length; ++i)
{
   // the rows must start at 1
   piechart.ChartData[i + 1, 0].Value = products[i];
   piechart.ChartData[i + 1, 1].Value = shares[i];
}


I still see all of the other data.

As long as I use that first set of lines the problem can be mitigated, but unless I'm doing something wrong the problem is still present.

sparticus1701
 
Posts: 5
Joined: Fri Jun 27, 2014 1:18 pm

Thu Jul 17, 2014 3:51 am

Hello,

Thanks for your feedback.
We design that when creating a chart, it will create a templete which initializes four rows data, and the new will cover the old when writing new data into chart data. If the new data less four rows, the uncovered old data will be retained.
In new version, we add a new parameter with bool type for AppendChart method,
AppendChart(ChartType type, RectangleF rectangle, bool init = true);
It is to decide whether initializing data when creating chart, if false, it will not, but you needs to configurate chart by yourself using the below code.
Code: Select all
    piechart.Series.Clear();
             piechart.Categories.Clear();
             piechart.Categories.CategoryLabels = piechart.ChartData["A2", "A4"];
             piechart.Series.SeriesLabel = piechart.ChartData["B1", "B1"];
             piechart.Series[0].Values = piechart.ChartData["B2", "B4"];



Best wishes,
Amy
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Presentation