+ Start a Discussion
NapsterNapster 

Visual force Charts problem

Hi friends,

 

I have a requirment where i have 4 select lists, one for time period, company, product 1 and product 2.

 

The requirment states that i have to show a measure for 2 metrics. Example : on a single line graph, 2 lines should be there where one line represents number of missed appointments for given time period for a given company for product 1. And the other line should represent missed appointments for the same given time for the same given company but for product 2.

 

I am not able to figure out what is causing the problem in the code. The problem identified is as below:

"Querying without an ascending order (by dates) plots data points on the graphs but not in an ASC order. When we query by ASCENDING order, the dates plot in an ascending order, but there is some data loss (I.e. some dates are not plotted on the graph). Also, the dates are repeated on the x axis."

Below the logic of how we are combining 2 different query's to show in a single graph:

"Take both query results and add them to a list simultaneously in a wrapper class. If results from the first query are greater than the second query. Add the remaining results of Query 1 to the list and pass 0 values for the query 2 and visa-versa."

 

This is the visual force code :

 

<apex:pageBlockSection title="Product Comparison" columns="1">
                <apex:pageBlockSectionItem >
                   <apex:outputPanel >
                        <b>Time :</b>&nbsp;
                        <apex:selectList title="Time Select" value="{!productCompareTimeSel}" multiselect="false" size="1">
                            <apex:selectOptions value="{!timeOptions}"/>
                        </apex:selectList>
                        
                        &nbsp;&nbsp;<b> CP Name : </b>&nbsp;
                        <apex:selectList title="CP Name" value="{!productCompareCPSel}" multiselect="false" size="1">
                            <apex:selectOptions value="{!cPOptions}"/>
                        </apex:selectList>
                        
                        &nbsp;&nbsp;<b> Product 1 : </b>&nbsp; 
                        
                        <apex:selectList title="Product" value="{!productCompareSel1}" multiselect="false" size="1">
                            <apex:selectOptions value="{!productOptions}"/>
                        </apex:selectList>
                        
                        &nbsp;&nbsp;<b> Product 2 : </b>&nbsp; 
                        
                        <apex:selectList title="Product" value="{!productCompareSel2}" multiselect="false" size="1">
                            <apex:selectOptions value="{!productOptions}"/>
                        </apex:selectList>
                        
                        &nbsp;&nbsp;
                        
                        <apex:commandButton value="Submit" action="{!productCompareSubmit}" reRender="thirdPageBlockSection" status="fetch-data3">
                        </apex:commandButton>
                        <apex:actionStatus startStyleClass="tab1" startText="Fetching Results..." id="fetch-data3"/>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            
             <apex:pageBlockSection title="Product Comparision" id="thirdPageBlockSection" columns="1" >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel ><b>Chart 5</b></apex:outputLabel><br/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:chart data="{!ProductCompareSummaries}" width="100%" height="400" rendered="{!NOT(ISNULL(ProductCompareSummaries))}" >
                        <apex:legend position="right"/>
                        <apex:axis type="Numeric" position="left" fields="OverAllMiss2,CustMiss2,openreachMiss2,OverAllMiss1,CustMiss1,openreachMiss1"
                             title="Percentage Missed(%)" grid="true" minimum="0" />
                        <apex:axis type="Category" position="bottom" fields="measureDate1,measureDate2" title="Measure Date" grid="true">
                            <apex:chartLabel rotate="-415"/>
                        </apex:axis>
                                               
                        <apex:lineSeries title="Missed App For {!productCompareSel1} - Openreach" axis="left" xField="measureDate1" yField="openreachMiss1"
                            fill="false" markerType="circle" markerSize="4" markerFill="Red" fillColor="#4F0101"/>
                        
                        <apex:lineSeries title="Missed App For {!productCompareSel1} - Customer" axis="left" xField="measureDate1" yField="CustMiss1"
                            fill="false" markerType="circle" markerSize="4" markerFill="Yellow" fillColor="#8F0101"/>
                        
                        <apex:lineSeries title="Missed App For {!productCompareSel1} - Overall" axis="left" xField="measureDate1" yField="OverAllMiss1"
                            fill="false" markerType="circle" markerSize="4" markerFill="Black" fillColor="#BF0101"/>
                        
                        
                        
                        <apex:lineSeries title="Missed App For {!productCompareSel2} - Openreach" axis="left" xField="measureDate2" yField="openreachMiss2"
                            fill="false" markerType="cross" markerSize="4" markerFill="Green" fillColor="#4F0101"/>
                        
                        <apex:lineSeries title="Missed App For {!productCompareSel2}  - Customer" axis="left" xField="measureDate2" yField="CustMiss2"
                            fill="false" markerType="cross" markerSize="4" markerFill="Blue" fillColor="#8F0101"/>
                        
                        <apex:lineSeries title="Missed App For {!productCompareSel2} - Overall" axis="left" xField="measureDate2" yField="OverAllMiss2"
                            fill="false" markerType="cross" markerSize="4" markerFill="Orange" fillColor="#BF0101"/>
                    </apex:chart>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

 

The following is my controller :

 

public Class Charts2Controller{

    public Date startDate,endDate;
    public String productCompareTimeSel {get; set;}
    public String productCompareSel1 {get; set;}
    public String productCompareSel2 {get; set;}
    public String productCompareCPSel { get; set; }
    public List<AggregateResult> PCAggrQueryResult {get;set;}
    public List<AggregateResult> PCAggrQueryResultP2 {get;set;}
    public List<ProductCompareSummary> ProductCompareSummaries{get;set;}


 public List<SelectOption> gettimeOptions () {
        List<SelectOption> timeOptions = new List<SelectOption>();
        timeOptions.add(new SelectOption('CM','Calendar Month')); 
        timeOptions.add(new SelectOption('RM','Rolling Month'));
        timeOptions.add(new SelectOption('CW','Calendar Week'));
        timeOptions.add(new SelectOption('RW','Rolling Week'));
        
        return timeOptions;
    }
    
    public List<SelectOption> getproductOptions () {
        List<SelectOption> productOptions = new List<SelectOption>();
        //productOptions.add(new SelectOption('ALL','--All--')); 
        productOptions.add(new SelectOption('LLU','LLU'));
        productOptions.add(new SelectOption('WLR3','WLR3'));
        productOptions.add(new SelectOption('FTTC','FTTC'));
        
        return productOptions;
    }

public List<SelectOption> getCPOptions(){
        List<SelectOption> CPOptions = new List<SelectOption>();
        CPOptions.add(new SelectOption('CP - 1','CP - 1'));
        CPOptions.add(new SelectOption('CP - 2','CP - 2'));
        CPOptions.add(new SelectOption('CP - 3','CP - 3'));
        CPOptions.add(new SelectOption('National','National'));
        
        return CPOptions;
    }

public List<AggregateResult> ProductCompareSelectQuery()
    {
        String query = 'Select Measure_Date__c, AVG(Missed_Appointment_Customer__c) CustMissed, AVG(Missed_Appointment_Openreach__c) openreachMissed, AVG(Missed_Appointment_Overall__c) overallMissed '+
                            'from Visual_Force_Reporting_Object__c '+
                                'Where CP_Name__c =: productCompareCPSel AND (Measure_Date__c >=: startDate AND Measure_Date__c <=: endDate) AND Product__c =: productCompareSel1 '+
                                    'Group By Measure_Date__c ';//Order By Measure_Date__c ASC ';
        
        System.Debug('ProductCompareSelectQuery queryabc : '+query);
        
        return Database.query(query);
    }
    
    public List<AggregateResult> ProductCompareSelectQueryP2()
    {
        String query = 'Select Measure_Date__c, AVG(Missed_Appointment_Customer__c) CustMissed, AVG(Missed_Appointment_Openreach__c) openreachMissed, AVG(Missed_Appointment_Overall__c) overallMissed '+
                            'from Visual_Force_Reporting_Object__c '+
                                'Where CP_Name__c =: productCompareCPSel AND (Measure_Date__c >=: startDate AND Measure_Date__c <=: endDate) AND Product__c =: productCompareSel2 '+
                                    'Group By Measure_Date__c ';//Order By Measure_Date__c ASC ';
        
        System.Debug('ProductCompareSelectQueryP2 : '+query); 
        
        return Database.query(query);
    }
*--------------------------Constructor START----------------------*/ 
public Charts2Controller(){
/	**********************INITIALIZATION FOR PRODUCT COMPARE----(LEVEL 3)********************/
        
        PCAggrQueryResult = new List<AggregateResult>();
        PCAggrQueryResultP2 = new List<AggregateResult>();
        
        ProductCompareSummaries = new LIST<ProductCompareSummary>();
        
        productCompareSel1 = 'LLU';
        productCompareSel2 = 'LLU';
        productCompareCPSel = 'CP - 1';
        
        PCAggrQueryResult = ProductCompareSelectQuery();
        PCAggrQueryResultP2 = ProductCompareSelectQueryP2();
                
        while(size1 < PCAggrQueryResult.size() && size2 < PCAggrQueryResultP2.size())
        {
            ProductCompareSummaries.add(new ProductCompareSummary(PCAggrQueryResult[size1],PCAggrQueryResultP2[size2]));
            
            size1++;
            size2++;
        }
        
        while(size1 < PCAggrQueryResult.size()) //Here we check if more results are pending to be added to the list. If so, we add results of the first query and 0 for the other query).
        {
            ProductCompareSummaries.add(new ProductCompareSummary(PCAggrQueryResult[size1],null));
            size1++;
        }
        while(size2 < PCAggrQueryResultP2.size()) //Here we check if more results are pending to be added to the list. If so, we add results of the first query and 0 for the other query).
        {
            ProductCompareSummaries.add(new ProductCompareSummary(null,PCAggrQueryResultP2[size2]));
            size2++;
        }
        
        System.Debug('PCAggrQueryResult : '+PCAggrQueryResult.size());
        System.Debug('PCAggrQueryResultP2 : '+PCAggrQueryResultP2.size());
        System.Debug('ProductCompareSummaries : '+ProductCompareSummaries.size());
        
        size1 = size2 = 0;
}

public PageReference productCompareSubmit()
    {
        integer size1=0,size2=0;
        
        if(productCompareTimeSel == 'CM'){
            startDate = Date.newInstance(Date.Today().year(),Date.Today().month(),1);
            endDate = startDate.addDays(Date.daysInMonth(Date.Today().year(),Date.Today().month()) - 1);
        }
        else if(productCompareTimeSel == 'RM'){
            startDate = Date.Today().addDays(-Date.daysInMonth(Date.Today().year(),Date.Today().month()));
            endDate = Date.Today();
        }
        else if(productCompareTimeSel == 'CW'){
            startDate = Date.Today().toStartofWeek();
            endDate = startDate.addDays(6);
        }
        else if(productCompareTimeSel == 'RW'){
            startDate = Date.Today().addDays(-6);
            endDate = Date.Today();
        }
        
        if(ProductCompareSummaries != null)
            ProductCompareSummaries.clear();
        
        PCAggrQueryResult = ProductCompareSelectQuery();
        PCAggrQueryResultP2 = ProductCompareSelectQueryP2();
        
        while(size1 < PCAggrQueryResult.size() && size2 < PCAggrQueryResultP2.size())
        {
            ProductCompareSummaries.add(new ProductCompareSummary(PCAggrQueryResult[size1],PCAggrQueryResultP2[size2]));
            
            size1++;
            size2++;
        }
        
        while(size1 < PCAggrQueryResult.size())  //Here we check if more results are pending to be added to the list. If so, we add results of the first query and 0 for the other query).
        {
            ProductCompareSummaries.add(new ProductCompareSummary(PCAggrQueryResult[size1],null));
            size1++;
        }
        while(size2 < PCAggrQueryResultP2.size())  //Here we check if more results are pending to be added to the list. If so, we add results of the first query and 0 for the other query).
        {
            ProductCompareSummaries.add(new ProductCompareSummary(null,PCAggrQueryResultP2[size2]));
            size2++;
        }
        
        System.Debug('PCAggrQueryResult : '+PCAggrQueryResult.size());
        System.Debug('PCAggrQueryResultP2 : '+PCAggrQueryResultP2.size());
        System.Debug('ProductCompareSummaries : '+ProductCompareSummaries.size());
        
        return null;
    }



 

 

Can some one please guide me as of where i am going wrong?
Your help is much appreciated.

 

Warm Regards,

Surya