我正在使用JFreeChart v1.0.19创建以下时间序列图:
...使用以下代码:
final String chartTitle = "";
final XYDataset dataset = createDataset1();
final JFreeChart chart = ChartFactory.createTimeSeriesChart(
chartTitle, "Year End", "Turnover", dataset, true, false, false);
final XYPlot plot = chart.getXYPlot();
final NumberAxis axis2 = new NumberAxis("Cash");
axis2.setAutoRangeIncludesZero(false);
plot.setRangeAxis(1, axis2);
plot.setDataset(1, createDataset2());
plot.mapDatasetToRangeAxis(1, 1);
final StandardXYItemRenderer renderer1 = new StandardXYItemRenderer();
renderer1.setSeriesPaint(0, Color.blue);
renderer1.setSeriesShape(0, ShapeUtilities.createDiamond(5));
renderer1.setSeriesShapesFilled(0, true);
plot.setRenderer(0, renderer1);
final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
renderer2.setSeriesPaint(0, Color.black);
renderer2.setSeriesShape(0, ShapeUtilities.createDiamond(5));
renderer2.setSeriesShapesFilled(0, true);
plot.setRenderer(1, renderer2);
chart.getPlot().setBackgroundPaint(Color.WHITE);
chart.getXYPlot().setDomainGridlinePaint(Color.LIGHT_GRAY);
chart.getXYPlot().setRangeGridlinePaint(Color.LIGHT_GRAY);
...但是我无法获得显示形状的数据点。这可能吗?
答案 0 :(得分:1)
问题出在我的渲染器上。从StandardXYItemRenderer
更改为XYLineAndShapeRenderer
,例如
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true,true);
...成功了。构造函数中的两个布尔args分别用于打开/关闭线条和形状。