i have created a google pie chart without date filters but now i wanted to 
show my chart according to dates (Date From and Date To)
i have an object named SERVICE__c and Case object
Service object having fields Service_Start_Date__c which i have used as 
Date From and other is system.today for Date To but when i click on Go 
button.. it is not showing me the result according to dates
this is my code
i wanted to check records for Last week,Last month,Last 90 Days, Last Year 
for this i have created four formula fields for each of them...u can check 
this in my service list

Visualforce Page:

<apex:page controller="DashPortalController" sidebar="false">
<apex:pageMessages ></apex:pageMessages>
<!-- Google API inclusion -->
<apex:includeScript id="a" value="https://www.google.com/jsapi"; />
<apex:sectionHeader title="Google Charts" subtitle="Chart 1"/>

<!-- Google Charts will be drawn in this DIV -->
<apex:form >

<table align="center">
<td><b>Date From:</b>
<apex:inputField value="{!servList.Service_Start_Date__c}" /></td>
<td><b>Date To:</b>
<apex:outputText value="{0,date,dd/MM/yyyy}">
<apex:param value="{!NOW()}" />
</apex:outputText></td>
<td><input type="button" onclick="*initCharts*()" value="Go"/></td>

</table>
<div id="chartBlock" style="width: 600px; height: 500px;"/>

<script type="text/javascript">
google.load('visualization', '1', {'packages':['corechart']});
google.setOnLoadCallback(initCharts);

function initCharts() {
DashPortalController.loadCustomerServiceSuccessRate(
function(result, event){
// load Column chart
var visualization = new 
google.visualization.PieChart(document.getElementById('chartBlock'));
var data = new google.visualization.DataTable();
data.addColumn('string','Success or Failure');
data.addColumn('number','Percentage');

var finalBean= result;
data.addRows([

['Service Success Rate', finalBean.totalServiceColl],
['Service Failure Rate', finalBean.totalCases]]);


visualization.draw(data,{title:'Service Success Rate',legend : {position: 
'bottom', textStyle: {color: 'blue', fontSize: 10}}, 
width:window.innerWidth,vAxis:{textStyle:{color:'red', fontSize: 15}}});
}, {escape:true});
}
</script>
</apex:form>
</apex:page>

 

*Controller Coding:*

 

global with sharing class DashPortalController{

public Service__c servList{get;set;}


@RemoteAction
global static CaseFailBean loadCustomerServiceSuccessRate(){

Map<Id,CaseFailBean> caseBeanMap=new Map<Id,CaseFailBean>();

map<id,Decimal> mapgrandParentsCounts = new map<id,Decimal>();
Service__c serviceList= [select 
id,Name,Service_Start_Date__c,Last_90_Days__c,
Last_Month__c,Last_Week__c,Last_Year__c
from Service__c s where Status__c = 'Active'
AND Customer__c!=null limit 1];
Date Last90days= serviceList.Last_90_Days__c;
Date LastWeek= serviceList.Last_Week__c;
Date LastMonth= serviceList.Last_Month__c;
Date LastYear= serviceList.Last_Year__c;
Date DateFrom= serviceList.Service_Start_Date__c;

List<Service__c> sr2= [select id, Name, Customer__c,Status__c, 
s.Customer__r.Grand_Parent_Account__c,
Week_Number__c,Count_of_Pickup_Days__c,Service_Start_Date__c
from Service__c s where Status__c = 'Active'
AND Count_of_Pickup_Days__c!=null AND Customer__c!=null AND 
Week_Number__c!=null
AND Service_Start_Date__c>=:LastMonth] ;

List<service__c> srList= [select id, Name, Customer__c,Status__c, 
s.Customer__r.Grand_Parent_Account__c,
Week_Number__c,Count_of_Pickup_Days__c,Service_Start_Date__c
from Service__c s where Status__c = 'Active'
AND Count_of_Pickup_Days__c!=null AND Customer__c!=null AND 
Week_Number__c!=null
AND Service_Start_Date__c>=:LastYear];

*if(DateFrom>=LastYear){*
for(Service__c sr:srList){
if(mapgrandParentsCounts.containskey(sr.Customer__r.Grand_Parent_Account__c) 
&& sr.Name!=null)
{
Decimal tCount = 
mapgrandParentsCounts.get(sr.Customer__r.Grand_Parent_Account__c);
tCount = tCount + (sr.Count_of_Pickup_Days__c * sr.Week_Number__c);
mapgrandParentsCounts.put(sr.Customer__r.Grand_Parent_Account__c,tCount);
}
else
{
mapgrandParentsCounts.put(sr.Customer__r.Grand_Parent_Account__c,(sr.Count_of_Pickup_Days__c
 
* sr.Week_Number__c));
}
}
}


List<Service__c> sr1 = [select id, Name, Customer__c,Status__c, 
s.Customer__r.Grand_Parent_Account__c,
Week_Number__c,Count_of_Pickup_Days__c,Service_Start_Date__c
from Service__c s where Status__c = 'Active'
AND Count_of_Pickup_Days__c!=null AND Customer__c!=null AND 
Week_Number__c!=null
AND Service_Start_Date__c>=:Last90days];
system.debug('========sr1=========='+sr1);
*if(DateFrom>=Last90days){*
for(Service__c srObj: sr1){
if(mapgrandParentsCounts.containskey(srObj.Customer__r.Grand_Parent_Account__c) 
&& srObj.Name!=null)
{
Decimal tCount = 
mapgrandParentsCounts.get(srObj.Customer__r.Grand_Parent_Account__c);
tCount = tCount + (srObj.Count_of_Pickup_Days__c * srObj.Week_Number__c);
mapgrandParentsCounts.put(srObj.Customer__r.Grand_Parent_Account__c,tCount);
}
else
{
mapgrandParentsCounts.put(srObj.Customer__r.Grand_Parent_Account__c,(srObj.Count_of_Pickup_Days__c
 
* srObj.Week_Number__c));
}
}
}*else if(DateFrom>=LastMonth){*
for(Service__c srObj1: sr2){
if(mapgrandParentsCounts.containskey(srObj1.Customer__r.Grand_Parent_Account__c)
 
&& srObj1.Name!=null)
{
Decimal tCount = 
mapgrandParentsCounts.get(srObj1.Customer__r.Grand_Parent_Account__c);
tCount = tCount + (srObj1.Count_of_Pickup_Days__c * srObj1.Week_Number__c);
mapgrandParentsCounts.put(srObj1.Customer__r.Grand_Parent_Account__c,tCount);
}
else
{
mapgrandParentsCounts.put(srObj1.Customer__r.Grand_Parent_Account__c,(srObj1.Count_of_Pickup_Days__c
 
* srObj1.Week_Number__c));
}
}
}




CaseFailBean beanList=new CaseFailBean();

for(id gpAcc : mapgrandParentsCounts.keyset()) {

system.debug('==========ServiceSuccessRate========='+ServiceSuccessRate);
system.debug('==========ServiceFailureRate========='+ServiceFailureRate);
CaseFailBean beanObj=new 
CaseFailBean(ServiceSuccessRate,ServiceFailureRate);
beanList=beanObj;

}

system.debug('==========beanList=========='+beanList);
return beanList;
}

global class CaseFailBean{
public Decimal totalCases{get;set;}
public Decimal totalServiceColl{get;set;}


public CaseFailBean(Decimal ServiceSuccessRate,Decimal ServiceFailureRate){
this.totalServiceColl=ServiceSuccessRate;
this.totalCases=ServiceFailureRate;
}

public CaseFailBean(){

}
}
}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-visualization-api/-/D74I7P5S0dMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-visualization-api?hl=en.

Reply via email to