我正在尝试将StandardXYItemLabelGenerator
与XYAreaRenderer2
渲染器一起使用,但没有任何内容出现。如果使用与XYLineAndShapeRenderer
相同的代码,我会正确地看到图表上的标签。如何在XYAreaChart
上看到这些标签?
// create the chart...
final JFreeChart chart = ChartFactory.createXYAreaChart(
header_label, // chart title
x_label, // x axis label
y_label, // y axis lsabel
dataset, // data
PlotOrientation.VERTICAL,
includeLegend, // include legend
true, // tooltips
false // urls
);
// NOW DO SOME OPTIONAL CUSTOMIZATION OF THE CHART...
chart.setBackgroundPaint(Color.white);
// get a reference to the plot for further customization...
final XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white); // X Axis is Domain
plot.setRangeGridlinePaint(Color.white); // Y Axis is Range
// Allow lines and shapes to be visible
renderer1 = new XYAreaRenderer();
// Set the tooltip generator
renderer1.setBaseToolTipGenerator(toolTipGenerator);
NumberFormat.getNumberInstance().setMaximumFractionDigits(2);
// renderer1.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator("{0} {1} {2}", NumberFormat.getNumberInstance(), NumberFormat.getNumberInstance()));
renderer1.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator("test {0} {1} {2}", NumberFormat.getNumberInstance(), NumberFormat.getNumberInstance()));
renderer1.setBaseItemLabelsVisible(true);
plot.setRenderer(renderer1);
答案 0 :(得分:3)
与XYLineAndShapeRenderer
不同,XYAreaRenderer
和XYAreaRenderer2
都不会调用抽象父级drawItemLabel()
。实际上,不支持标签,但工具提示如下所示。
XYAreaRenderer2 renderer = new XYAreaRenderer2(
new StandardXYToolTipGenerator("test: {0} {1} {2}",
NumberFormat.getNumberInstance(),
NumberFormat.getNumberInstance()), null);
plot.setRenderer(renderer);