I am facing problems with Bar chart of Ireport. In Pie Charts, for legend and legend labels I use 0,1,2 and display values along with their percentages. I want to do a similar thing for Bar Charts. I want to display the value for each bar along its category as below.
Across forums, suggestions have been placed to use customizer class. Is there a simpler way to do what I require? If I need to use customizer class, is there a sample available? I am using the latest I report and jasper server 5.0
Any help would be highly appreciated. Thanks
2 Answers:
Hi
It is possible with 'Show Label' option as well as 'class customizer' as Shertage said, If 'show label' option already checked then unchecked it and again checked so that it works.
Thanks Ajinkya. Yes, I unchecked and checked again to get the 'Show Labels' property to get the values and it did work. For the shortest bar, the value doesn't get displayed. I reduced the font size to the possible level('6' to be precise) where users can view the values, but the shortest bar doesn't show the value since it is very small in size. Is there something I need to do so that value is displayed for the shortest bar?
Also, could you please tell how to display values for Line chart as well?
I have the same requirement for line chart... Could anyone help me on this topic?
Thanks Sanda. Could you please tell me how to display values for Line chart as well?
For now there is no 'Show Labels' attribute for the line plot. But you can render the labels visible using a chart customizer:
public void customize(JFreeChart chart, JRChart jasperChart){
LineAndShapeRenderer lineRenderer = (LineAndShapeRenderer)chart.getCategoryPlot().getRenderer();
lineRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
lineRenderer.setBaseItemLabelsVisible(true);
}
If it's an XY line chart, use an XYPlot and a StandardXYItemLabelGenerator in the above code snippet.
I hope this helps,
sanda
This works like a charm for Line Charts. Thanks a ton.I had a query for Bar Charts. Show labels works for bar Chart. But the value of the shortest bar doesn't get displayed. I reduced the font size to the possible level('6' to be precise) where users can view the values, but the shortest bar doesn't show the value since it is very small in size. Is there something I need to do so that value is displayed for the shortest bar?
Do you have a printscreen, or a test sample that illustrates this problem? I couldn't reproduce it locally.
Thanks,
sanda
Thanks Sanda for all your inputs. It really helped me . I forgot to mention Bar Chart 3D. I have now changed it into 2D Bar Chart and it works perfectly. I will surely paste the sample for future references. Thanks again.
Hi Rasmi,
Could you explain me how to use these chart customizer in iReport, because i have no idea about java.