You need to sign in to do that
Don't have an account?
Google charts
having problem in chart because i have used array so it shows me 1 record at 1 time through vf page. but i want to show all the records if any one can help me in this
this is my code
Visualforce page:
<apex:page controller="WasteSplit" sidebar="false">
<!-- Google API inclusion -->
<apex:includeScript id="a" value="https://www.google.com/jsapi" />
<apex:sectionHeader title="Google Charts" subtitle="Chart 2"/>
<!-- Google Charts will be drawn in this DIV -->
<div id="chartBlock" />
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(initCharts);
function initCharts() {
WasteSplit.WasteSource(
function(result, event){
// load Column chart
var visualization = new google.visualization.PieChart(document.getElementById('chartBlock'));
var finalBean=result[0];
// Prepare table model for chart with columns
var data = new google.visualization.arrayToDataTable([
['Cases','Success Rate'],
['Total Waste',finalBean.wastetype]
]);
// add rows from the remoting results
// all done, lets draw the chart with some options to make it look nice.
var opt={title:[finalBean.WasteName],pieSliceText:['value']};
visualization.draw(data,opt);
},{escape:true});
}
</script>
</apex:page>
=========================================================================
controller class:
global with sharing class WasteSplit{
@RemoteAction
global static WasteSplitt[] WasteSource(){
Map<String,Integer> countMap = new Map<String,Integer>();
List<Service__c> sList = [select Name,Waste_Type2__c,s.Customer__r.Grand_Parent_Account__c,Status__c
from Service__c s where Status__c = 'Active' and Waste_Type2__c!=null];
system.debug('========sList======'+sList);
for(Service__c sr: sList){
ID parentAccountId=sr.Customer__r.Grand_Parent_Account__c;
if(countMap.get(sr.Waste_Type2__c)==null)
{
countMap.put(sr.Waste_Type2__c,1);
}
else
{
integer cnt=countMap.get(sr.Waste_Type2__c);
countMap.put(sr.Waste_Type2__c,cnt+1);
}
}
WasteSplitt[] SplitList = new WasteSplitt[countmap.size()];
system.debug('========splitlist======'+splitlist);
Integer i=0;
for(String WasteTypeField : countMap.keySet()){
system.debug('========countMap.keySet()======'+countMap.keySet());
system.debug('========WasteTypeField======'+WasteTypeField);
WasteSplitt beanObj=new WasteSplitt(WasteTypeField,countMap.get(WasteTypeField));
system.debug('========beanObj======'+beanObj);
SplitList[i]=beanObj;
i++;
}
system.debug('========SplitList======'+SplitList);
return SplitList;
}
global class WasteSplitt{
public String WasteName{get;set;}
public Integer wastetype{get;set;}
public WasteSplitt(String wastename,Integer waste){
this.WasteName=wastename;
this.wastetype = waste;
}
public WasteSplitt(){
}
}
}
Debug shows all the values but in chart it shows only 1st value becuase of this in vf page var finalBean=result[0];
========SplitList======(WasteSplitt:[WasteName=Cardboard Stickers, wastetype=86], WasteSplitt:[WasteName=Dry Mixed Recycling, wastetype=1135], WasteSplitt:[WasteName=Electrical, wastetype=49], WasteSplitt:[WasteName=Brake fluid, wastetype=5], WasteSplitt:[WasteName=Clinical, wastetype=1], WasteSplitt:[WasteName=Food, wastetype=21]
thanks for ur time....:)
I don't think you are using the google API correctly. The arrayToDataTable needs multi-dementional array of the data. Easier would be to try to initialize the data using addRow method. Sample is given below.
All Answers
I don't think you are using the google API correctly. The arrayToDataTable needs multi-dementional array of the data. Easier would be to try to initialize the data using addRow method. Sample is given below.
thanks....it works