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.

Wed Nov 17, 2021 6:41 pm

Hello,
we are evaluating Spire.Presentation for one of our projects. therefor i need to know is it possible to change the chart data of a existing file.
for example let's assume that there is a doughnut chart with following data

{ "Categoty 1" : "100" }
{ "Categoty 2" : "200" }
{ "Categoty 3" : "300" }

and i want to update this chart with following values

{ "Categoty 4" : "400" }
{ "Categoty 5 : "500" }
{ "Categoty 6" : "600" }
{ "Categoty 6" : "700" }

Can you please let me know if this is doable or not. if this is possible to do, a code example would be highly appreciated.
Thank you

charith.wick
 
Posts: 2
Joined: Mon Nov 15, 2021 2:15 pm

Thu Nov 18, 2021 6:38 am

Hello,

Thanks for your inquiry.
Please refer to the code below to update the chart data source. If there is any question, please feel free to contact us.
Code: Select all
Presentation ppt = new Presentation();
ppt.LoadFromFile("input.pptx");
IChart chart = ppt.Slides[0].Shapes[0] as IChart;     
string[] values1 = new string[] { "Categoty 4", "Categoty 5", "Categoty 6", "Categoty 7" };
int[] values2 = new int[] { 400, 500, 600, 700 };
for (int i = 0; i < values1.Length; ++i)
{
    chart.ChartData[i + 1, 0].Value = values1[i];
    chart.ChartData[i + 1, 1].Value = values2[i];
}
chart.Categories.CategoryLabels = chart.ChartData["A2", "A5"];
chart.Series[0].Values = chart.ChartData["B2", "B5"];

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Thu Nov 25, 2021 8:55 am

Hi,

Hope you are doing well!
How is your issue going? Did the code we provided work for you? Any feedback will be greatly appreciated.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Presentation