0

I am trying to make it that every element in the arraylist needs_elements is populated on a graph. Right now I am doing it very repetitively. My code is below:

ArrayList

   Root C = gson.fromJson(profile.toString(), Root.class);
   ArrayList<Double> percentagesList = new ArrayList();
   Root.SubTree t = C.getSubTree(); //Gets subtree from root
   ArrayList<Children> c = t.getChildren(); 
   Children needs = c.get(1);
   ArrayList<Children1> needsChildren = needs.getChildren();
   Children1 needsChildren1 = needsChildren.get(0);
   ArrayList <Children2> needs_elements = needsChildren1.getChildren(); //ELEMENTS FROM THIS ARRAYLIST 

My way

         double CHTotal = 0;        
          percentagesList.add(needs_elements.get(0).getPercentage());
          CHTotal = needs_elements.get(0).getPercentage();
          System.out.println(CHTotal);

//--------------Barchart-----------------------------------------------------
          dcd.setValue(CHTotal, "Percentage", "Openness"); //Show here 
          JFreeChart jchart = ChartFactory.createBarChart3D("Arrays", "Types","Percentage" , dcd, PlotOrientation.VERTICAL,true,true,false ); //chart
            CategoryPlot plot = jchart.getCategoryPlot();
            ChartFrame chartFRM = new ChartFrame("Student Records", jchart,true);  
            chartFRM.setVisible(true);
            chartFRM.setSize(500,400);

I have to do this for about 10+ elements. Is there a way I can automatically get each element in the needs_elements arraylist and make it increment in the barchart? Thanks for your time:)

Alia Su
  • 45
  • 1
  • 2
  • 9
  • Just update the `DefaultCategoryDataset` is place; the listening chart will update itself in response. – trashgod Nov 29 '16 at 21:26
  • How do I do that? – Alia Su Nov 29 '16 at 21:39
  • This [example](http://stackoverflow.com/a/21267585/230513) is typical; if this is not a duplicate, please edit your question to include a [mcve] that shows your revised approach. – trashgod Nov 30 '16 at 03:24

0 Answers0