我已经在JFreeChart中创建了一个饼图。然而,“分片”上没有出现数值。我该如何让它显示出来?
我已经在JFreeChart中创建了一个饼图。然而,“分片”上没有出现数值。我该如何让它显示出来?
PiePlot
上,可以使用 setSimpleLabels
方法实现此功能。Chart chart = // your created chart
PiePlot plot = (PiePlot) chart.getPlot();
plot.setSimpleLabels(true);
如果你需要更简单的外观,可以使用透明颜色来设置标签阴影、轮廓和背景绘制:
plot.setOutlinePaint(new Color(0, 0, 0, 0));
plot.setLabelShadowPaint(new Color(0, 0, 0, 0));
plot.setLabelBackgroundPaint(new Color(0, 0, 0, 0));
plot.setLabelOutlinePaint(new Color(0, 0, 0, 0));
编辑:显示切片中的值而不是图例:
plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}"));
StandardPieSectionLabelGenerator
还有一个数字格式化器,如果您需要的话可以使用它。BarRenderer
上的 setPositiveItemLabelPositionFallback(ItemLabelPosition position)
方法设置标签位置。对于内部标签,您可以使用以下代码:barRenderer.setPositiveItemLabelPositionFallback(
new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
barRenderer.setNegativeItemLabelPositionFallback(
new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
- codixsetPositiveLabelPositionFallback
。如果你有 JFreeChart 的开发者手册,可以查阅标签锚点/位置的定义。 - Jes