一切似乎都运转良好,唯一的问题是应该生成的图表是一个没有相互连接的条形图,但我最终得到的图表并不是我想要的图表。
我关注了视频,代码似乎相似,所以我无法弄清楚出了什么问题:
try {
int rubyPoints = Integer.parseInt(getHP("Ruby"));
int amberPoints = Integer.parseInt(getHP("Amber"));
int pearlPoints = Integer.parseInt(getHP("Pearl"));
int sapphirePoints = Integer.parseInt(getHP("Sapphire"));
DefaultCategoryDataset barChartData = new DefaultCategoryDataset();
barChartData.setValue(rubyPoints, "House Points", "Ruby");
barChartData.setValue(amberPoints, "House Points", "Amber");
barChartData.setValue(pearlPoints, "House Points", "Pearl");
barChartData.setValue(sapphirePoints, "House Points", "Sapphire");
JFreeChart barChart = ChartFactory.createAreaChart("House Points",
"All houses", "Amount of points", barChartData, PlotOrientation.VERTICAL, false, true, false);
CategoryPlot barchrt = barChart.getCategoryPlot();
barchrt.setRangeGridlinePaint(Color.BLUE);
ChartPanel barPanel = new ChartPanel(barChart);
panelChart.removeAll();
panelChart.add(barPanel, BorderLayout.CENTER);
panelChart.validate();
} catch (IOException ioe) {
// error handling
}
图表看起来像这样(这不是我需要的样子):