2
我试图创建一个条形图,在for循环中生成一个数据集。JFreeChart条形图生产
String scores = scoreText.getText();
String[] data = scores.split(",");
DefaultCategoryDataset barChartDataset = null;
for (int l = 0; l < data.length; l++) {
barChartDataset = new DefaultCategoryDataset();
// barChartDataset.setValue(new Double(data[l]), "Scores", stu);
barChartDataset.addValue(new Double(data[l]), "Scores", stu);
System.out.println(data[l]);
}
JFreeChart barChart = ChartFactory.createBarChart3D("Summary", "Name", "Scores", barChartDataset, PlotOrientation.VERTICAL, false, true, false);
的数据是10,5
。现在,当数据通过所有这些并生成图形时,仅显示值为5的条。价值10的单独栏在哪里?有谁知道我做错了什么?任何帮助表示赞赏。由于
编辑: 下面是条形图代码:我猜你正在做的一个小失误
String scores = scoreText.getText();
String[] data = scores.split(",");
DefaultCategoryDataset barChartDataset = new DefaultCategoryDataset();
//JFreeChart barChart = null;
for (int l = 0; l < data.length; l++) {
//barChartDataset.addValue(new Double(data[l]), "Scores", stu);
barChartDataset.setValue(new Double(data[l]), "Scores", stu);
System.out.println(new Double(data[l]));
}
JFreeChart barChart = ChartFactory.createBarChart3D("Summary", "Name", "Scores", barChartDataset, PlotOrientation.VERTICAL, false, true, false);
barChart.setBackgroundPaint(Color.YELLOW);
barChart.getTitle().setPaint(Color.RED);
final CategoryPlot categoryPlot = barChart.getCategoryPlot();
BarRenderer barRenderer = (BarRenderer) categoryPlot.getRenderer();
DecimalFormat decimalFormat = new DecimalFormat("#.##");
barRenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalFormat));
categoryPlot.setRenderer(barRenderer);
barRenderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.HALF_ASCENT_CENTER));
barRenderer.setItemLabelsVisible(true);
barChart.getCategoryPlot().setRenderer(barRenderer);
ValueMarker marker = new ValueMarker(7);
marker.setLabel("Required Level");
marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
marker.setPaint(Color.BLACK);
categoryPlot.addRangeMarker(marker);
categoryPlot.setRangeGridlinePaint(Color.BLUE);
//The JFrame that the bar chart will be in.
ChartFrame chartFrame = new ChartFrame("Bar Chart for Parameters", barChart);
chartFrame.setVisible(true);
chartFrame.setSize(600, 600);
不幸的是,它没有解决问题。 – Navio53
尽我所知,它必须解决您所陈述的问题。最近我与JfreeChart库一起工作。我正在编辑我的答案并放入我的工作代码片段。看看,我希望它可以帮助你。 –
我要编辑我的问题,我发布条形图的整个代码。我试过你的代码,它的工作原理。我试图让我的模型尽可能类似你的,但问题没有解决。 – Navio53