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.

Thu Oct 14, 2021 1:07 pm

Objective:
We have designed a column chart by hand in PowerPoint, see "chart template" image below.
chart template.PNG

We want to replace the data behind the chart using spire.presentation.
We want the chart not to lose any of its visual formatting which we set by hand.
We want to simply connect to the chart shape, access the data behind it and replace it with new data.
We do not want to control the chart's visual formatting through code.
We do not want to copy the formatting of one series and apply it to another through code.

Problem:
If the data we want to add has more data values than what was originally in the chart then those data values are not automatically shown in the chart.

This is the data I want to add:

chart.ChartData[1, 0].Value = "Samsung";
chart.ChartData[2, 0].Value = "Apple";
chart.ChartData[3, 0].Value = "Google";
chart.ChartData[4, 0].Value = "Xiaomi";
chart.ChartData[5, 0].Value = "Huawei";
chart.ChartData[6, 0].Value = "Oppo";
chart.ChartData[7, 0].Value = "Alcatel";

chart.ChartData[1, 1].Value = 0.1;
chart.ChartData[2, 1].Value = 0.25;
chart.ChartData[3, 1].Value = 0.6;
chart.ChartData[4, 1].Value = 0.2;
chart.ChartData[5, 1].Value = 0.3;
chart.ChartData[6, 1].Value = 0.1;
chart.ChartData[7, 1].Value = 0.4;

The data range behind the chart is not automatically expanded to include the new data value. See "missing data values" image.
missing data values.PNG


Question:
how do we expand the data range behind the chart to include the new data values so that we don't have to control the visual format of the data value through code.

majeed_s
 
Posts: 69
Joined: Thu Mar 25, 2021 4:13 pm

Fri Oct 15, 2021 6:07 am

Hello Majeed,

Thanks for your inquiry.
For your requirement, please just change the data for category labels and each series.
Code: Select all
  chart.Categories.CategoryLabels = chart.ChartData["A2", "A8"];
  chart.Series[0].Values = chart.ChartData["B2", "B8"];


Sincerely,
Amy
E-iceblue support team
User avatar

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

Fri Oct 22, 2021 8:09 am

Dear Majeed,

Hope you are doing well.
Has your issue been solved?
Looking forward to your feedback.

Sincerely,
Amy
E-iceblue support team
User avatar

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

Return to Spire.Presentation