Hello Aspose,
I have a simple docx with a single bar chart in it.
The bar chart has already been setup with all the styles, etc that are needed.
All I need to automate is a push into the chart of new data value.
I can’t find any way in the API to do this.
Can you point me at the correct way to do this?
Thanks
We suggest you please remove the chart series and add them again. Please check the following code example and read the following article. Hope this helps you.
Working with Charts
Document document = new Document(MyDir + "input.docx");
Shape shape = (Shape)document.GetChild(NodeType.Shape, 0, true);
if (shape.HasChart)
{
Chart chart = shape.Chart;
chart.Series.Clear();
String[] types = new String[] { "text1", "text2", "text3" };
double[] values = new double[] { 10d, 7d, 5d };
ChartSeries ser0 = chart.Series.Add("test", types, values);
}
document.Save(MyDir + "out.docx");
Thanks for the swift response.
I tried the recommended solution and while it does work for pushing the data in, when the series is cleared it removes all of the formatting, styles, colors, etc that the business has setup.
Is there a way to just update the data without affecting the visual aspects of the chart?
To ensure a timely and accurate response, please attach the following resources here for testing:
- Your input Word document.
- Please attach the output Word file that shows the undesired behavior.
- Please attach the expected output Word file that shows the desired behavior.
- Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.
As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.
PS: To attach these resources, please zip and upload them.
Is there anyway to just update data of series? Not deleting existing series.
If we delete existing series, all formatting for that series gets lost.
@snehalghute Yes, this feature is available starting from 23.5 version of Aspose.Words. Please see Aspose.Words 23.5 version release notes for more information:
https://docs.aspose.com/words/net/aspose-words-for-net-23-5-release-notes/#implemented-ability-to-get-and-modify-chart-series-data