简体   繁体   中英

Implementation of Gchart for dynamic data

I have used Gchart to display data in chart form. For now the chart is static. I need to make the chart dynamic as the chart values may change time and again. My Code is like this:

dynamicChartObj = new GChartModelBuilder().setChartType(GChartType.PIE).build();
dynamicChartObj = new GChartModelBuilder()
                    .setChartType(GChartType.PIE)  
                    .addColumns("Topping", "Slices")
                    .addRow("A", 12)  
                    .addRow("B", 20)
                    .addRow("C", 39)
                    .addRow("D", 45)
                    .build();  
<div id="savChart">
      <pe:gChart value="#{dashboardMB.dynamicChartObj}" width="400" height="400"
      title="Quanity Wise">
      </pe:gChart>
</div>

I need to add rows dynamically. How can i do this?

Finally i figured out the solution for my problem. My solution for the problem is like this:

GChartModelBuilder chartBuilder = new GChartModelBuilder();
chartBuilder.setChartType(GChartType.PIE);
chartBuilder.addColumns("Topping", "Slices");
HashMap<String, Double> valuesOfChart = prepareRowsOfChart(); 
for (Map.Entry pair : valuesOfChart.entrySet()) {
    chartBuilder.addRow((String) pair.getKey(), ((double) pair.getValue()));
}
chartSavingModel = chartBuilder.build();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM