You need to sign in to do that
Don't have an account?
Sindhu Vm
Need Help - to dynamically populating GeoChart in Visualforce page
Hi, I created a VF page and loaded Google GeoChart with static data and it worked fine. But then I wrote a controller to query the db as AggerateResult. Now my map does not work when I loop though the AggregateResult in VF page to populate the data for GeoChart.
I’m new to coding and not sure if I’m referencing the Aggregate Result properly in Vuisualforce page. Please help.
Here is the apex code:
Here is the VF code:
The part of the VF code which is an issue is:
I’m new to coding and not sure if I’m referencing the Aggregate Result properly in Vuisualforce page. Please help.
Here is the apex code:
public with sharing class testCon { Public AggregateResult[] myData{get; set;} Public Integer Count{get; set;} Public testCon() { myData = [SELECT Collateral_State__c State, Count(Name) NbrOfCollaterals FROM Collateral__c where Overall_Status__c = 'Active' and Collateral_State__c != null group by Collateral_State__c ]; Count = Integer.valueOf(myData.size()); } Public AggregateResult[] getmyData() { return myData; } }
Here is the VF code:
<apex:page controller="testCon" readOnly="true"> <apex:includeScript value="https://www.gstatic.com/charts/loader.js" /> <apex:includeScript value="https://www.google.com/jsapi" /> <script type="text/javascript"> google.charts.load('current', { 'packages':['geochart'],'mapsApiKey': 'MyKey' }); var cnt = {!Count}; google.charts.setOnLoadCallback(drawRegionsMap); function drawRegionsMap() { var data = new google.visualization.DataTable(); data.addColumn('string', 'State'); data.addColumn('number', 'Number of Collaterals'); data.addRow(['Illinois',1]); // Just a sample static data for illustration for(AggregateResult rs : {!myData}) { data.addRow([rs.State,rs.NbrOfCollaterals]); } var options = { region: 'US', displayMode: 'markers', backgroundColor: '#75a3e7', datalessRegionColor: '#f2f2f2', colorAxis: {colors: ['green', 'blue'] } }; //Getting the GeoChart Div Container var chart = new google.visualization.GeoChart(document.getElementById('chart_div')); //Drawing the GeoChart with Data and Options chart.draw(data, options); } </script> <div id="chart_div" style="width: 900px; height: 500px;"></div> </apex:page>
The part of the VF code which is an issue is:
for(AggregateResult rs : {!myData}) { data.addRow([rs.State,rs.NbrOfCollaterals]); }
Try below Code. that javascript looping is not the issue. from controller to VF page MYDate was not parsing correctly. here is the complate code.
Class
VF page :
NOTE: Remove alerts after you finished testing.
Hope this will works for you.
Thanks
karthik
All Answers
Try below Code. that javascript looping is not the issue. from controller to VF page MYDate was not parsing correctly. here is the complate code.
Class
VF page :
NOTE: Remove alerts after you finished testing.
Hope this will works for you.
Thanks
karthik
This is the map rendered when I use only hardcoded data.