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

Free Support Forum - aspose.com

Legend entry: can't get it from the Chart object

I load xlsx document with the chart into library and then try to get LegendEntry of the chart - it seems that library simply does not see them. Is it supported at all? Or you just created some stubs?
Also follow up question on this: how can I change text for LegendEntry. API doesn’t seem to have some functions for that? It’s no use for us, if it doesn’t allow to change its text.

Snippet of code I used below and file attached.

License license = new License();
license.setLicense(new FileInputStream(“Aspose.Total.Java.lic”));
Workbook wb = new Workbook(PATH_TO_FILE + “\” + FILE_NAME);
Chart testChart = wb.getWorksheets().get(0).getCharts().get(0);
LegendEntryCollection legendEntryCollection = testChart.getLegend().getLegendEntries();
int countLegendEntries = legendEntryCollection.getCount();
System.out.println(“countLegendEntries=” + countLegendEntries);

Hi,


Thanks for sharing the template file.

1) After an initial test, I can notice the issue as you have mentioned. Aspose.Cells always gives legend entries’ count to “0”. I have logged a ticket with an id “CELLSJAVA-40516” for your issue. We will look into it soon.
Once we have any update on it, we will let you know here.

2) You may set the source name of the series for the respective legend entry to change its text/label, see the following line of code:
//Change the first legend entry name.
testChart.getNSeries().get(0).setName(“Custom Legend Entry”);


Thank you.

Thanks for the tip on how to change label.
I will then use SeriesCollection for legend entry enumeration.

Hi,


Good to know that it works for you.
And, we will continue to look into your logged issue and if we have any update on it, we will let you know here.

Thank you.

Hi,


Please try the new fix/version: Aspose.Cells for Java v7.4.3.5.


You can changes the text and font by the following code segment.<o:p></o:p>

//Changes
text of legend item<o:p></o:p>


testChart.getNSeries().get(0).setName(“Custom Legend Entry”);<o:p></o:p>

<o:p></o:p>

//By default,
getLegendEntries() is no entry. Create a object by calling
legendEntryCollection.get(0)<o:p></o:p>

LegendEntry entry =
legendEntryCollection.get(0);<o:p></o:p>

//Changes font color of
legend item<o:p></o:p>


entry.getFont().setColor(Color.getRed());<o:p></o:p>

Thank you.

Thanks. I wasn’t expecting it so quickly.

Hi,

Let us know if you still encounter any other issue, please feel free to post on forum, we will be glad to help you further.

Thank you.