Is there a way to include some arbitrary text in the legend in a JFreeChart PieChart? I know it\'s possible to assign a PieSectionLabelGenerator
in order to customi
I have a Multi Axis chart that i recently built and came up with this scheme to distinguish the time periods i was displaying using a line chart to show the previous 12 months imposed over a bar chart showing the current 12 months.
If you want to add text before your other series so that your legend looks something like this:
Previous 12 Months: * charges * adj * cash Current 12 Months: * charges * adj * cash
where the *'s are the shapes/colors of your series. (i would have included a pic, but i dont have enough rep points ... this is my first post to stack overflow =) )
Then i would suggest adding a series and making it the first series in your chart(s) (series 0). Name this series whatever text you want to display (my example is "Previous 12 Months: ". Then you can use some java to customize series 0 so that the data is not show on the chart, but you still get the label in the legend.
This is what my custmoize method for making a line chart line/shape not visible:
@Override
public void customize(JFreeChart chart, JRChart jasperChart) {
LineAndShapeRenderer renderer = (LineAndShapeRenderer) chart.getCategoryPlot().getRenderer();
renderer.setSeriesLinesVisible(0, false);
renderer.setSeriesShapesVisible(0, false);
etc ....
}
If it is another type of chart like the bar chart then just make series 0's color to match the background and give it a value like 1. Note that this does add more space between the bars! The extra space between the bars on my chart made it look better, but this wouldn't be a good solution if you like the spacing between your charts bars.
Not sure if this is useful for answering the initial question but its another option for anyone looking to add text the their charts legend.
Enjoy!