2

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?

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Mani Ratna
  • 883
  • 1
  • 11
  • 30

1 Answers1

2

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();
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Mani Ratna
  • 883
  • 1
  • 11
  • 30