In my case I have a chart with a secondary Y axis. Is there a way to access the legends of that secondary axis? I would like to update the legend text and hide other ones.
I have been able to access only the primary Y axis legends with this code:
Chart chart = shape.Chart;
ChartSeriesCollection seriesColl = chart.Series; // Items in seriesColl will be primary axis only
You can get the chart legend using Chart.Legend property. Could you please ZIP and attach your input Word document and expected output? We will then provide you more information about your query.
I need to edit the text of the elements inside the legends box and remove Secondary Chart series as well.
I have attached a zip with the files. There are 3 files:
The template for the chart.
The current output.
The expected output.
You will notice that in the template there are 10 chart series: 5 primary (1 to 5) and 5 secondary (6 to 10).
It is expected that data will be related between the 2 axis. So, in the example of the expected output you will find data for 3 people, where:
Person 1 => Serie1 and Serie6
Person 2 => Serie2 and Serie7
Person 3 => Serie3 and Serie8
It is expected that series 4, 5, 9 and 10 should be deleted since were not used. Also it is expected that in the legend box each person appear only 1 time. Since I’m updating the text for the legends corresponding to the Primary Series, the legend corresponding to the secondary series should be hidden.
So as I mentioned in my first post, I don’t have issues implementing this behavior for the primary series legends, however I don’t have a clue of how to do it with the secondary series legends.
Unfortunately, Aspose.Words does not support the requested feature at the moment. However, we have logged this feature request as WORDSNET-20643 in our issue tracking system. You will be notified via this forum thread once this feature is available.
Please do not use static series name in the template document. You can use an expression that will be evaluated dynamically instead of a static series name.
For series to be removed from the chart based upon conditions dynamically, define the conditions in names of these series using removeif tags having the following syntax.
If this does not work for you, 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 along with your data source object. We will investigate the issue and implement your requirement accordingly.
The information supplied was very helpful. Some stuff such as axis titles, series names and other things can be done using the LINQ queries. However it didn’t work for all cases. I have updated the template using LINQ queries and also I have attached a working sample project.
I have a couple of questions here:
How can I manage correctly the indexes in the template in order to avoid the “index out of range” exception? For example in the sample project it is passing the serie names in a list of strings named serieNames and in the template it is accessing them by index. However template is expecting 5 serie names tops but in code it only sets 3 series. So serieNames[3] and serieNames[4] will throw index out of range exception.
Also from the sample project, the class named WordChartDataSource has a property named SerieName. Code is passing a list of this elements to the template. Could you please supply an example of how can I set correctly the serie names using that property?
Please run the supplied code and generate the sample report. I was able to set up the removeif statement to remove unused series from the chart including the ones for the secondary axis. However I still need to hide from the legend box the legends corresponding to the secondary axis but keeping the data in the chart. As you will see in the sample report, legends in the legends box appear twice and they should appear only once. Could you help with this too?
Hi @tahir.manzoor,
I have attached again the sample project, this time if you run it you will get the index out of range exception. The source code is exactly the same as the previous time. The change is in the template, I just added serieName[3] and serieName[4] to the series 7, 8, 9 and 10. Code is just setting values for serieName[0], serieName[1] and serieName[2].
Regarding WORDSNET-20643, we have closed this issue as ‘Not a bug’.
Starting from Aspose.Words 20.7, you can remove chart legend entries corresponding to duplicates from a template. Then the duplicates do not appear in a result document. To remove a chart legend entry in a template using MS Word, it is required to select the entry and press Delete.
We have closed the issue WORDSNET-20689 as ‘Not a bug’.
This can be done using the same syntax as would be used in C#. That is, expression serieNames[0] can be replaced with expression dataSource[0].SerieName. Please check the attached template document. WORDSNET-20689.zip (22.5 KB)
It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue WORDSNET-20692 as ‘Not a Bug’.
In order to avoid the exception, you need to use the same approach as would be used in C#. For example, expression <<[serieNames[3]]>> can be replaced with expression <<[3 < serieNames.Count ? serieNames[3] : ""]>>. Please check the attached modified template document. WORDSNET-20692.zip (22.4 KB)