Free Support Forum - aspose.com

Set DataLabels values visible

Hi,

I need to make DataLabels values visible.

I try to use:

chart.getNSeries().get(0).getDataLabels().setShowValue(true)

but it doesn't work.

Insteas if I use this:

chart.getNSeries().get(0).getDataLabels().setValueShown(true);

it work, but this method is deprecated.

Which method should I use? There is a bug on setShowValue(true) method?

Thanks.

Hi,


Well, you may still use setValueShown(), it will work.

For setShowValue() method, I have tested it with the following sample code and it works fine.

Sample code:
// Obtaining the reference of the first worksheet
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get(0);
ChartCollection charts = sheet.getCharts();
int chartIndex = charts.add(ChartType.COLUMN, 5, 0, 15, 5);
Chart chart = charts.get(chartIndex);

Cells cells = sheet.getCells();
cells.get(“A2”).putValue(“Category”);
cells.get(“B1”).putValue(“Value1”);
cells.get(“B2”).setFormula("=NA()");

cells.get(“C1”).putValue(“Value2”);
cells.get(“C2”).putValue(2d);

SeriesCollection nSeries = chart.getNSeries();
nSeries.add(“B2:C2”, true);

// set labels for every series
nSeries.setCategoryData(“A2”);
nSeries.get(0).setName("=B1");
nSeries.get(1).setName("=C1");

// show values
nSeries.get(0).getDataLabels().setShowValue(false);
nSeries.get(1).getDataLabels().setShowValue(true);

// save excel
workbook.save(“outmytesting.xls”);
System.out.println(“finished”);

I am using v7.0.2.4, please try it:
https://forum.aspose.com/t/122557

thank you.