We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Word merge chart and configure colors

We merging charts into a Word template bases on a mergefield. So in the template someone put a [Chart] and we replace it in the mergefieldhander by someting like this:


Shape shape = builder.insertChart(type, chartMx.getWidth(), chartMx.getHeight());
// Chart property of Shape contains all chart related options.
com.aspose.words.Chart chart = shape.getChart();
chart.getTitle().setText(chartMx.getCaption());
// add series

The disadvantage of this is that the chart isn’t visible in the word template and all configuration like chart title, colors e.t.c have to be done from code.

Question 1: is there an other way to merge a chart into a word template so that the user can configure the chart in the Word template (just as a normal chart) and from code I only have to merge the data.

If this is not possible than my second question is relevant:

Question 2: Can I configure the colors used by the chart / series from code. I can only find SetFillColor on the Shape object, but I want to configure the color of each serie. Series are added as data arrays without any configuration possibility, so it seems.

Thanks!

Hi Herbert,


Thanks for your inquiry. Regarding Q1, after an initial test with Aspose.Words for Java 16.1.0, we were unable to reproduce this issue on our end. We would suggest you please upgrade to the latest version of Aspose.Words. Hope, this helps.

Regarding Q2, please use Chart class and its properties/methods such as ChartLegend, ChartSeriesCollection and ChartTitle to be able to programmatically configure various aspects of Chart.

Best regards,

Hi Awais,


This is not really help full. Regarding question 1, I’m not talking about a bug, i’m asking how to do something. I don’t want to create and configure a chart from code but just insert data into the template.

Regarding question two, can you provide more details (code example): how to change bar chart (serie) colors from code.

Hi Herbert,


Thanks for your inquiry. Regarding Question 1, can you please take a look at this example and see if this is what you’re asking about? You can get required test template document from here. If not, then please elaborate your usecase further with the help of your sample template and code. Thanks for your cooperation.

Herbert:
Question 2: Can I configure the colors used by the chart / series from code. I can only find SetFillColor on the Shape object, but I want to configure the color of each serie. Series are added as data arrays without any configuration possibility, so it seems.
We will add feature in Aspose.Words to get/set chart series colors. Your thread has been linked to the appropriate issue (WORDSNET-12640) and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Best regards,

Hi Awais,


Thank you. The links seems to do what I want. To not built the chart from code but just add it as a regular word chart. I can do all the (color) configuration in the Word template.

I will try it.

Regarding question 2: the issue you mentioned is for WordsNet? I’m using words-Java.

Thanks.

Hi Herbert,


Thanks for your inquiry. Please note that the latest version of Aspose.Words for Java is completely auto-ported from .NET, i.e. we do not write code for Aspose.Words for Java; it is generated out automatically from C# code of Aspose.Words for .NET. In your case, the issue, that was previously logged with WORDSNET prefix, would be auto resolved for Java variant of Aspose.Words as well. Your problem will be fixed as soon as the linked issue is resolved. We will inform you via this thread as soon as this issue is resolved.

Best regards,

The issues you have found earlier (filed as WORDSNET-12640) have been fixed in this Aspose.Words for .NET 21.6 update and this Aspose.Words for Java 21.6 update.