Search code examples
javajfreechart

Showing both values and series names in JFreeChart


enter image description here

I have a stacked bar chart like in the image above. What i need is to show both series names and values on each bar. How can i do that?

I can show series with this code:

renderer.setBaseItemLabelGenerator(
            new StandardCategoryItemLabelGenerator("{0}", NumberFormat.getInstance()));

Solution

  • I found the way to show both of them. The trick is to define each parameters format sequentially. Here is the code:

           renderer.setBaseItemLabelGenerator(
    new StandardCategoryItemLabelGenerator("{0} {2}", NumberFormat.getInstance(),NumberFormat.getNumberInstance()));