JFreeChart饼图上的注释
-
05-07-2019 - |
题
具体而言,我希望将特定位置的文本注释添加到JFreeChart,该JFreeChart将输出到png文件以供Web使用。可以/如何将注释添加到饼图中。我已经能够成功地向XYPlots添加注释,但不知道如何覆盖或添加一个PiePlot。
我的全部任务是使用PiePlot创建一种时钟。到目前为止,一切都很好,但现在我需要在12点,3点,6点和9点位置添加标签并完全难倒。
亚当
解决方案 2
经过相当费力的搜索,我认为目前不可能(JFreeChart 1.0.13)。 可能的选择是:
使用XYPlot创建第二个图表,以生成带有所需注释的第二个图像。在页面上叠加此图像。此选项很糟糕,因为它会使要上传的图表图像数量翻倍。
将图像设置为页面上的背景,并将图像设置为HTML。不好,因为它不可维护,并且令数据传输头疼。
就我个人而言,我只想找到另一种方式来传达标题中的信息,但我想将结果发布给下一个人。 亚当
其他提示
这是一个古老的问题,但这里我是如何使用极坐标绘制类似的东西(在1,2,3,......位置注释)。它使用ChoiceFormatter和NumberTickUnit:
final JFreeChart chart = ChartFactory.createPolarChart(
"HAPI Hourly Usage (UTC)", ds, true, true, false);
final PolarPlot plot = (PolarPlot) chart.getPlot();
// Create a ChoiceFormat to map the degrees to clock positions
double[] limits = new double[12];
String[] formats = new String[12];
limits[0] = 0;
formats[0] = "12";
// degrees = 360/12
for (int i = 1; i < limits.length; i++) {
limits[i] = degrees * (i);
formats[i] = Integer.toString(i);
}
ChoiceFormat clock = new ChoiceFormat(limits, formats);
TickUnit tickUnit = new NumberTickUnit(degrees, clock);
// now configure the plot
plot.setAngleTickUnit(tickUnit); // sets the ticks
plot.setAngleLabelsVisible(true); // makes the labels visible
plot.setAngleLabelPaint(Color.LIGHT_GRAY); // user choice
plot.setAngleGridlinesVisible(true); // must set this to display the
// labels
plot.setAngleGridlinePaint(Color.BLACK); // plot's background color
// (makes lines invisible)
plot.setRadiusGridlinesVisible(false); //turn off the radius value circles
ValueAxis axis = plot.getAxis();
axis.setTickLabelsVisible(false); //turn off the radius value labels
不隶属于 StackOverflow