Pivot chart java cells

Hi Team,
How i can get the numbers to displayed on the pivot charts (column stacked chart) ?Please find attach the pivot table and chart.

Looking forward for your response.

Thanks,
Nidhi

@Nidhi.chawhan

Thanks for your posting and considering Aspose APIs.

We are unable to find your attachment. It seems, you have forgotten to attach it. Please provide us your sample Excel file(s), we will look into your issue and help you out.

please find attach excel sheet.Asposechart.zip (9.3 KB)

Please look into this issue.

Thanks,
Nidhi

@Nidhi.chawhan

Thanks for your Excel file. We will investigate this issue with your provided Excel file and update you asap.

Ok i will wait for your response.

Thanks,
Nidhi

Hi team ,
in chart type api i cannot see the clustered_column chart.
i got COLUMN_3_D_CLUSTERED chart type.
Is someother name given to it?

Looking forward for your reply.

Thanks,
Nidhi

@Nidhi.chawhan

ChartType.COLUMN is actually a clustered column chart, so please use it for your needs.

Thanks Shakeel. it worked for me .
my next question is
how i can remove the null values from the chart ?
in my previous sheet i requested :-
how i can add data labels to the chart

Looking forward for your reply.

Hi,
How i can add data labeles to charts?
i tried doing this

DataLabels dataLabels = chart.getNSeries().get(0).getDataLabels();
dataLabels.setShowPercentage(true);
but it gives exception as array index oout of bound exception because chart.getNSeries() is [].

Can you please check this issue?

Thanks,
Nidhi

@Nidhi.chawhan

Please see the following sample code, its source Excel file and output Excel file as well as the following screenshot for your help.

Download Link:
Download Files.zip (20.1 KB)

Java

//Load source Excel file
Workbook wb = new Workbook(dirPath + "sampleChart.xlsx");

//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);

//Access first chart
Chart ch = ws.getCharts().get(0);

//Access data labels of first series
DataLabels dataLabels = ch.getNSeries().get(0).getDataLabels();

//Show data labels and position them
dataLabels.setShowValue(true);
dataLabels.setPosition(LabelPositionType.OUTSIDE_END);

//Save the output Excel file
wb.save(dirPath + "outputChart.xlsx");

Screenshot:

Hi team,

Thank you for the quick response.
Atcually i already tried this piece of code .
DataLabels dataLabels = chart.getNSeries().get(0).getDataLabels();
but it gives exception as array index oout of bound exception because chart.getNSeries() is []. Can you please check this issue?

Looking forward for your reply.

Thanks,

@Nidhi.chawhan

Please check how many series are present inside your chart. It seems, there is no series inside your chart.

Print the count of series like this

Java

//Check the number of series inside the chart
System.out.println("Number of Series: " + ch.getNSeries().getCount());

@Nidhi.chawhan

Thanks for considering Aspose APIs.

Please see the following code and its output Excel file and its screenshot for your help.

Download Link:
Output-Excel-File.zip (7.3 KB)

Java

// Create workbook
Workbook wb = new Workbook(FileFormatType.XLSX);

// Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);

// Add column stacked chart
int idx = ws.getCharts().add(ChartType.COLUMN_STACKED, 6, 2, 30, 15);

// Access chart
Chart ch = ws.getCharts().get(idx);

// Set category data
ch.getNSeries().setCategoryData("{IA,EVAL,FITNESS}");

// Add series
int idx1 = ch.getNSeries().add("{70,5,1}", false);
int idx2 = ch.getNSeries().add("{67,4,2}", false);
int idx3 = ch.getNSeries().add("{23,0,0}", false);

// Access all series
Series srs1 = ch.getNSeries().get(idx1);
Series srs2 = ch.getNSeries().get(idx2);
Series srs3 = ch.getNSeries().get(idx3);

// Set series names
srs1.setName("NEGATIVE");
srs2.setName("POSITIVE");
srs3.setName("POSITIVE_WITH_RESERVATION");

// Show data labels
srs1.getDataLabels().setShowValue(true);
srs2.getDataLabels().setShowValue(true);
srs3.getDataLabels().setShowValue(true);

// Save the workbook
wb.save(dirPath + "Output.xlsx");

Screenshot: