I'm trying to create a bar chart that generates a dataset from within a for loop.
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);
The data is 10,5
. Now when the data goes through all of this and the graph is generated, only the bar for the value 5 is shown. Where is the separate bar for the value of 10? Does anyone know what I'm doing wrong? Any help is appreciated. Thanks
EDIT: Here is the code for the bar graph:
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);