我正在尝试运行以下代码,它在 getSeriesVisible 上引发异常:
chart.addChangeListener(new ChartChangeListener() {
int indexChanged = -1;
@Override
public void chartChanged(ChartChangeEvent event) {
XYPlot ff = chart.getXYPlot();
XYItemRenderer y = ff.getRenderer();
boolean b = y.getSeriesVisible(0);
// chart.getXYPlot().getRenderer().setSeriesVisible(0, b);
}
});
消息:线程“AWT-EventQueue-0”中的异常 java.lang.NullPointerException
有任何想法吗?
更新:我添加了几个系列并生成图表如下:
XYSeriesCollection data = new XYSeriesCollection();
XYSeries series = new XYSeries("Series 1", true);
series.add(1, 2);
series.add(3, 5);
series.add(8, 10);
series.add(11, 3);
series.add(8, 10);
data.addSeries(series);
series = new XYSeries("Series 2");
series.add(5, -2);
series.add(7, 6);
series.add(8, 12);
series.add(11, -2);
series.add(15, 10);
data.addSeries(series);
final JFreeChart chart = ChartFactory.createXYLineChart("Chart", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false);