In order to convey additional information, I am trying to replicate a specific functionality: embedding icons within the sector labels when using JFreeChart.
It should look something like this illustrated example I created with ChartDirector:
How do I achieve that?
One approach is to use the desired Unicode glyph, for example. Simply add the code point to the label string and use that string in the PieDataset<String>
, as shown in this complete example. The string will appear in the label. Because the PieSectionLabelGenerator
returns an AttributedString
, you can alter the size and location as shown here and here.
private static final String KEY1 = " 😀 Datum 1";
…
var dataset = new DefaultPieDataset<String>();
dataset.setValue(KEY1, 99);
…
var chart = ChartFactory.createPieChart(
"Header", dataset, true, true, false);