I add charts to a page programmatically. All charts work fine except GEO chart. Following is the code where I create the chart and set the value expression for the model. 'panelGrid' is the component on my web page where I add the chart:
Code: Select all
org.primefaces.extensions.component.gchart.GChart chart = new org.primefaces.extensions.component.gchart.GChart();
ValueExpression valueEx1 = app.getExpressionFactory().createValueExpression(f.getELContext(), "#{homePage.chartModelForReport}", GChartModel.class);
chart.setValueExpression("value", valueEx1);
panelGrid.getChildren().add(chart);
Code: Select all
GChartModel geoChartModel = null;
GChartModelBuilder chartBuilder = new GChartModelBuilder();
Map<String, Object> colorAxis = new HashMap<String, Object>();
String[] colorRanges = new String[2];
colorRanges[0] = "yellow";
colorRanges[1] = "red";
colorAxis.put("colors", colorRanges);
chartBuilder.addOption("colorAxis", colorAxis);
chartBuilder.addOption("region", "TR");
chartBuilder.addOption("resolution", "provinces");
chartBuilder.addOption("displayMode", "regions");
chartBuilder.setChartType(GChartType.GEO);
HashMap<String, double[]> valuesOfChart = prepareRowsOfChart(); //prepare rows
Collection<String> columns = prepareColumnsOfChart(); //prepare columns
chartBuilder.addColumns(columns);
for (Map.Entry pair : valuesOfChart.entrySet()) {
chartBuilder.addRow((String) pair.getKey(), ((double[]) pair.getValue())[0], ((double[]) pair.getValue())[1]);
}
geoChartModel = chartBuilder.build();
Code: Select all
<div id="mainForm:GEOCHART" class="ui-g-12 ui-md-12 ui-lg-12 ui-g-nopad">
<input id="mainForm:GeoChart_0_0_hidden" name="mainForm:GeoChart_0_0_hidden" type="hidden" />
<div id="mainForm:GeoChart_0_0"></div>
<script id="mainForm:GeoChart_0_0_s" type="text/javascript">PrimeFaces.cw("ExtGChart","widget_mainForm_GeoChart_0_0",{id:"mainForm:GeoChart_0_0",chart:"{\"type\":\"GeoChart\",\"options\":{\"region\":\"TR\",\"resolution\":\"provinces\",\"colorAxis\":{\"colors\":[\"yellow\",\"red\"]},\"displayMode\":\"regions\"},\"data\":[[[\"Key\",\"\"]],[\"\",4311.0],[\"İSTANBUL\",11529.0],[\"ADANA\",299.0],[\"VAN\",16.0]]}"});
</script>
</div>
Thanks.