Adding text not related to sections into Legend in JFreeChart PieChart

后端 未结 3 607
清酒与你
清酒与你 2021-02-06 17:44

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

3条回答
  •  名媛妹妹
    2021-02-06 18:20

    Looking at the source code of org.jfree.chart.JFreeChart, and seeing that addLegend() is nothing more than addSubtitle() behind the scenes, everything indicates that this should be achieved using addSubtitle().

    Looking at the part where org.jfree.chart.JFreeChart adds its own LegendTitle item, we can find the setup JFreeChart uses for placing the Legend here.

    So, the solution is to add, for instance, a TextTitle to the Chart in an analogous way. The relevant setting here is setPosition(RECTANGLE.BOTTOM).

    TextTitle legendText = new TextTitle("This is LEGEND: ");
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    

提交回复
热议问题