Update chart data point value

I need to edit values in a line and bar chart embedded within a Word document using Aspose Words. I haven’t found anything specifically covering this in the Words documentation. Is there a way to do this?

Thank you!

@chipoxendine

Can you please provide more details about the specific chart you are trying to update and the values you want to change?

There are several different types in each document: pie graphs, line graphs, bar charts and stacked column charts. In each case, several data point values vary between users of the document and these need to be updated individually from a central data store.

We’re using Words for C# and have the data available to the Words for C# library, but don’t know how to use the library to achieve these updates.

@chipoxendine You can use the following code to update chart’s data:

Document doc = new Document("ScatterChart.docx");

Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
Chart chart = shape.Chart;
ChartSeries series1 = chart.Series[0];

// Clear X and Y values of the first series.
series1.ClearValues();

// Populate the series with data.
series1.Add(ChartXValue.FromDouble(3), ChartYValue.FromDouble(10));
series1.Add(ChartXValue.FromDouble(5), ChartYValue.FromDouble(5));
series1.Add(ChartXValue.FromDouble(7), ChartYValue.FromDouble(11));
series1.Add(ChartXValue.FromDouble(9), ChartYValue.FromDouble(17));

ChartSeries series2 = chart.Series[1];

// Clear X and Y values of the second series.
series2.ClearValues();

// Populate the series with data.
series2.Add(ChartXValue.FromDouble(2), ChartYValue.FromDouble(4));
series2.Add(ChartXValue.FromDouble(4), ChartYValue.FromDouble(7));
series2.Add(ChartXValue.FromDouble(6), ChartYValue.FromDouble(14));
series2.Add(ChartXValue.FromDouble(8), ChartYValue.FromDouble(7));

doc.Save("out.docx");

Please see our documentation for more information:
https://reference.aspose.com/words/net/aspose.words.drawing.charts/chartseries/add/#add