I have a requirement to display negative values in pie chart in jasper reports.I am able to achieve this using customizer class.In createCustomizedDataset method I am checking if value is negative then later on while generating label I am appending "-" sign
PiePlot piePlot = (PiePlot) chart.getPlot();
PieDataset dataset = piePlot.getDataset(); // line 1
PieDataset dataset1 = createCustomizedDataset(dataset,piePlot);
piePlot.setDataset(dataset1);
StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(
"{1}") {
@SuppressWarnings("rawtypes")
@Override
public String generateSectionLabel(PieDataset dataset, Comparable key) {
String label = super.generateSectionLabel(dataset, key);
if(dataSetKeys.contains(key.toString())){
return "-"+label;
}else{
return label;
}
}
};
Output is below :
ISSUE IS : if there are multiple entries for negative values I am getting a different category with negative values combined.At line 1 the dataset key for these negative values is 'Other'.Here I have two categories one with value as "-2.02" and one with "-0.01". So instead of showing two slices it is showing one slice of 2.02+0.01=2.03.Problem is the dataset in customize method is like that.
I got it resolved as in chat edit wizard minimum expression was set to 0.Remove that to solve the issue.