我试图让arylylist needs_elements
中的每个元素都填充在图表上。现在我正在重复这样做。我的代码如下:
的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
我的方式
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);
我必须为大约10多个元素做这件事。有没有办法可以自动获取needs_elements
arraylist中的每个元素并使其在条形图中增加?谢谢你的时间:)