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

Free Support Forum - aspose.com

Advice about best way to copy formatting properties from one ChartEx to another?

Hi Mudassir,

I wanted to get your advice about working with ChartEx objects, if I may.

Let’s say I have a PPTX file that contains one slide, and on that slide is a ChartEx, which contains some sample data and has been formatted to look at certain way. I’m pulling some data from a database to populate the ChartDataWorkbook.

My challenge is that when I clear the Series data (using chart.CahrtData.Series.Clear()) and the Category data, the formatting that was previously specified on the “template” is cleared too, and thus my output PPTX has the right data, just not the same formatting choices as the “template”.

Since objects like the ChartDataLabelsEx aren’t clonable, I can’t easily make a copy of those values from the template, and then apply them later to the output PPTX.

So my current strategy is simply to set the original Chart as “Hidden”, create a new Chart (which gets populated with the data) and then attempt to copy anything that can be formatted from the “source chart” to the “target chart”.

So my question is: do you have any suggestions on copying the formatting form one ChartEx to another? It’s just a painstaking operation to copy each property from say ChartFormat.Effect object, since there are so many properties.

Any advice on transferring the format of one chart to another would be appreciated.

~~ Michael

Hi Michael,

I have observed the requirements shared and like to share that you are right in saying that when the chart series and categories are cleared then default formatting is set for newly added series or categories. I can offer you two solutions in this regard. Firs is that you write some method where by you pass on source and target series and the method copies that formatting from one series to another. This would be one time effort and you will just need and one line statement in your code for every series or categories. For idea about this approach please visit this documentation link.

The second and better approach is that you use your template chart and do not clear its default categories or series that holds the formatting information. You must have a chart with say 10 series and 10 categories. I said 10 so that you have the upper limits for series and categories numbers. The template chart series and categories may hold dummy data. You access that chart series and categories and update its data with one from your database. In the end you may remove the extra series or categories. I suggest you this approach as it is more smart and less time consuming.

Please share, if I may help you further in this regard.

Many Thanks,

Unfortunately I’ll have to go with the more difficult path because the templates are built by a wide variety of people and I won’t be able to enforce that they’ll have enough dummy data to ensure it’ll work every time.

Thanks for the thoughts.

Hi Michael,

You are always welcome. Please share, if I may help you further in this regard.

Many Thanks,