Java – Custom datapoint labels in JfreeChart

javajfreechart

I have an XYSeries to which I add values from a HashMap. I'd like the datapoints on the graph to have labels on them based on the key value in the HashMap.

So my question is, how do you create custom data point labels in JFreeChart?

Best Answer

An XYItemLabelGenerator works well. If the standard one, discussed here, is not sufficient, you can always override generateLabel() to access your Map.

Addendum: In outline, your generator would look something like this:

private static class MyGenerator implements XYItemLabelGenerator {

    @Override
    public String generateLabel(XYDataset dataset, int series, int item) {
        return "Series " + series + " Item " + item;
    }
}

And you would install it in your renderer as shown in the example.