Re: Not showing records according to the selected dates and Button click not working

53 views
Skip to first unread message

asgallant

unread,
Sep 17, 2012, 11:31:47 AM9/17/12
to google-visua...@googlegroups.com
This looks like an issue with your server side code, not the Visualization API.  I'd help you if I could, but I don't know visualforce.

On Monday, September 17, 2012 5:35:17 AM UTC-4, nishh wrote:
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(){

}
}
}

nishh

unread,
Sep 18, 2012, 12:35:38 AM9/18/12
to google-visua...@googlegroups.com
i have a problem in my button click. in this form i have  a GO button
so when i select any date then it will go to initCharts() and then go to controller and then in  loadCustomerServiceSuccessRate 

<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>
     </apex:form> 
<script type="text/javascript">
        //var DateFrom = document.getElementById('accountNameToSearch').value;
        google.load('visualization', '1', {'packages':['corechart']});
        google.setOnLoadCallback(initCharts);
   
        function initCharts() {         
             DashPortalController.loadCustomerServiceSuccessRate(
                 function(result, event){
                     if (event.type == 'exception') {
                         alert(event.message);
                     } else {  
                     // 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>

I wanted to show the date in controller which i have selected on VF page
global with sharing class DashPortalController{

    public Service__c servList{get;set;}
    
    public DashPortalController(){
        
    }
    
    @RemoteAction   
    global static CaseFailBean loadCustomerServiceSuccessRate(){
Reply all
Reply to author
Forward
0 new messages