Home Salesforce.com Displaying Salesforce data in Google Image Charts

Displaying Salesforce data in Google Image Charts.
We have a requirement to display the accounts
i) having cases more than 5 in red color.
ii) having cases equal to 5 in yellow color.
iii) having cases less than 5 in green color.
Client needs two buttons monthly and weekly.
If client clicks on Monthly, it should show the month report and when clicked on Weekly it should show the past week report.
For this, we need to develop a VF page with a custom controller in Salesforce.
Here is the Apex class where we build URL. to which we need to hit the google.

public class googlechartcls{        public googlechartcls(ApexPages.StandardController controller) {      dt=System.now().addDays(-7);      System.debug('-----dt is+'+dt);      lstcase =[Select account.name,casenumber, origin, reason,status,status__c,subject,LastRespondedDateTime__c,Age__c  from Case WHERE CreatedDate >=: dt and status != 'Closed' and account.name!=null];      List aggres = new List();      aggres=[Select account.name,count(id) from Case WHERE CreatedDate = THIS_Week and status != 'Closed' and account.name!=null  group by account.name];      chart(aggres);      }        public List getLstcases() {          return lstcase;      }        public List lstcase;      public datetime dt{get; set;}      public void tdays() {          dt=System.now().addDays(-30);          aggres=[Select account.name,count(id) from Case WHERE CreatedDate >=: dt and status != 'Closed' and account.name!=null  group by account.name];          lstcase =[Select account.name,casenumber,origin, reason,status,status__c,subject,LastRespondedDateTime__c,Age__c from Case WHERE CreatedDate >=: dt and status != 'Closed' and account.name!=null];          chart(aggres);      }        public void sdays() {      dt=System.now().addDays(-7);      aggres=[Select account.name,count(id) from Case WHERE CreatedDate = THIS_WEEK and status != 'Closed' and account.name!=null  group by account.name];      lstcase =[Select account.name,casenumber,origin, reason,status,status__c,subject,LastRespondedDateTime__c,Age__c from Case WHERE CreatedDate = THIS_WEEK and status != 'Closed' and account.name!=null];      chart(aggres);      }    List aggres;    public googlechartCls(){  }    public void chart(List aggres){      imgurl='';      System.debug(aggres);      imgurl='http://chart.apis.google.com/chart?chxt=x,y&chbs=a&chbh=a&chds=0,15&chs=450x250&chdlp=b|l&cht=bvg&chxs=0,68228B,12|1,68228B&chdls=330033,12&chtt=Account+Status+Report';      string chco='';      string chd='';      String chxr='';      String chxl='0:|';      String chm='';      String chdl='';      String chxs='';      Integer s;      for (integer i=0; i'+aggres);          if(i 5){                      chco+= 'ED1B0E|';                      chd += aggres[i].get('expr0')+',';                      chxl += string.valueof(i+1)+'|';                      chm +='t'+s+',0000FF,0,'+i+',10|';                      chdl+=string.valueof(i+1)+'='+aggres[i].get('Name')+'|';                    }                  else if(s == 5){                      chco += 'FDD017|';                      chd += aggres[i].get('expr0')+',';                      chxl +=string.valueof(i+1)+'|';                      chm +='t'+s+',0000FF,0,'+i+',10|';                      chdl+=string.valueof(i+1)+'='+aggres[i].get('Name')+'|';                    }                  else{                      chco+= '41A317|';                      chd += aggres[i].get('expr0')+',';                      chxl +=string.valueof(i+1)+'|';                      chm +='t'+s+',0000FF,0,'+i+',10|';                      chdl+=string.valueof(i+1)+'='+aggres[i].get('Name')+'|';                  }          }          else{          System.debug('Else Part');                  if( s > 5){                      chco+= 'ED1B0E';                      chd += aggres[i].get('expr0');                      chxl +=string.valueof(i+1)+'|';                      chm +='t'+s+',0000FF,0,'+i+',10';                      chdl+=string.valueof(i+1)+'='+aggres[i].get('Name');                    }                  else if(s == 5){                      chco += 'FDD017';                      chd += aggres[i].get('expr0');                      chxl +=string.valueof(i+1)+'|';                      chm +='t'+s+',0000FF,0,'+i+',10';                      chdl+=string.valueof(i+1)+'='+aggres[i].get('Name');                    }                  else{                      chco+= '41A317';                      chd+= aggres[i].get('expr0');                      chxl +=string.valueof(i+1)+'|';                      chm +='t'+s+',0000FF,0,'+i+',10';                      chdl+=string.valueof(i+1)+'='+aggres[i].get('Name');                  }          }      }        imgUrl+='&chco='+chco+'&chd=t:'+chd+'&chxl='+chxl+'|1:|0|5|15|20&chm='+chm+'&chdl='+chdl;    }    public string imgurl{get; set;}    }

**************************************************************************************************
Visual Force page:

      




    


c.id}">{!c.casenumber} {!c.account.name}
 
 
Here is the output:
 
 

I think this will help to give start with google charts .

You may also like

Leave a Comment