+ Start a Discussion
❤Code❤Code 

Apex:chart not displaying on vf page

Hi All,

I am using the below code to display chart on vf page . But it is not displaying anything. Can anyone have a look- 
 
public with sharing class wrapper_test_controller {
public list<wrapperclass> wrapperelement_for_account{get;set;}
public list<wrapperclass> wrapperelement_for_contact{get;set;}
public string selectedproductfamily {get;set;}
public list<Work_Order_Item__c> queryResult{get;set;}

public List<SelectOption> getproductfamily(){
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('None', 'None'));
        options.add(new SelectOption('Bedding', 'Bedding'));
        options.add(new SelectOption('Flooring', 'Flooring'));
        options.add(new SelectOption('Seating', 'Seating'));
        options.add(new SelectOption('Wall Treatments', 'Wall Treatments'));
        options.add(new SelectOption('Other', 'Other'));
        
        return options;
}

    public PageReference query() {
    system.debug('@@@'+selectedproductfamily);

        String qryString = 'select Product__r.Measurement_Type__c,Product__r.Treatment_Unit_Price__c,Product__r.Cleaning_Unit_Price__c,Product__c,Product__r.Name,Product__r.Family,id,name,Service__c,Quantity__c,Length__c,Width__c from Work_Order_Item__c WHERE ' +

            '(Product__r.Family like \'%' + selectedproductfamily + '%\')';

        queryResult = Database.query(qryString);
        
        return null;

    }

//list<Product2> object1 = [select id,name,Family,Measurement_Type__c,Treatment_Unit_Price__c,Cleaning_Unit_Price__c from Product2 limit 10];
//list<Work_Order_Item__c> object2 = [select Product__r.Measurement_Type__c,Product__r.Treatment_Unit_Price__c,Product__r.Cleaning_Unit_Price__c,Product__c,Product__r.Name,Product__r.Family,id,name,Service__c,Quantity__c,Length__c,Width__c from Work_Order_Item__c limit 10];

public wrapper_test_controller (ApexPages.StandardController controller) {

 }

//public list<wrapperclass> getaccountwrapperret(){
//wrapperelement_for_account = new list<wrapperclass>();
//for(Product2 obj1: object1){
//wrapperelement_for_account.add(new wrapperclass(obj1));
//}
//return wrapperelement_for_account;
//}
public list<wrapperclass> getPieData() {
 List<wrapperclass> data = new List<wrapperclass>();

List<Work_Order_Item__c> memb = new List<Work_Order_Item__c>();  
        

 AggregateResult[] groupedResults  = [SELECT count(Id) c, Product__r.Family f
        FROM Work_Order_Item__c
        WHERE Product__r.Family != null
        GROUP BY Product__r.Family];
 
 system.debug('@@@@'+ groupedResults);
 system.debug('@@@@'+ groupedResults.size());
 for (AggregateResult ar : groupedResults)  {            
                   
                     data.add(new wrapperclass(
                         String.ValueOf(ar.get('f')),
                         Double.ValueOf(ar.get('c'))
                         ));
                        
             }      
             return data; 
 
}
public class wrapperclass{
public String name { get; set; }  
 public Decimal data { get; set; }  
public Product2 object_account_1{get;set;}
public Work_Order_Item__c object_contact_2{get;set;}

public wrapperclass(Product2 obj1){
this.object_account_1 = (obj1);
}
public wrapperclass(Work_Order_Item__c obj2){
this.object_contact_2 = (obj2);}
public wrapperclass(String name, Decimal data) {
 this.name = name;  
 this.data = data;  
}
}
}

VF PAge - 
 
<apex:page standardController="Work_Order__c" extensions="wrapper_test_controller">
    <apex:form >
        <apex:pageblock id="pb">
        
        <apex:pageblockSection title="Work Order Details">
         <apex:inputField label="Account" value="{!Work_Order__c.Account__c}" required="true"/>
         
         <apex:inputField label="Status" value="{!Work_Order__c.Status__c}" required="true"/>
          <apex:inputField label="Service Date" value="{!Work_Order__c.Service_Date__c}" required="true"/>
        
        
        </apex:pageblockSection>
        <apex:pageblockSection title="Summary">
        
        <apex:chart height="350" width="450" data="{!pieData.size}">
            <apex:pieSeries dataField="data" labelField="Name"/>
            <apex:legend position="bottom"/>
        </apex:chart>
        
        
        </apex:pageblockSection>
                 <apex:pageblocksection title="Products" >
               
               <apex:outputPanel title="Family">
               <apex:outputLabel value="Family:"> &nbsp;&nbsp;
               <apex:actionRegion >              
                <apex:selectList value="{!selectedproductfamily}" size="1" label="Family"  rendered="true" >
                    <apex:actionSupport action="{!query}" reRender="pb1" id="fam" event="onchange"/> 
                    
                    <apex:selectOptions value="{!productfamily}" />
                    
                </apex:selectList>
                   </apex:actionRegion> 
                   </apex:outputLabel>
                   </apex:outputPanel>  
            </apex:pageblocksection>
          </apex:pageBlock>
          
          <apex:pageBlock id="pb1" mode="edit">  
         <apex:pageblocktable value="{!queryResult}" var="acc">
          <apex:column value="{!acc.Product__r.Name}" />
          <apex:column value="{!acc.Product__r.Family}" />
          <apex:column value="{!acc.Product__r.Measurement_Type__c}" />
          <apex:column value="{!acc.Product__r.Treatment_Unit_Price__c}" />
          <apex:column value="{!acc.Product__r.Cleaning_Unit_Price__c}" />
          <apex:column headerValue="Service">
          <apex:inputfield value="{!acc.Service__c}"/>
          </apex:column>
          
          <apex:column headerValue="Quantity">
          <apex:inputfield value="{!acc.Quantity__c}"/>
          </apex:column>
          
           <apex:column headerValue="Length">
          <apex:inputfield value="{!acc.Length__c}"/>
          </apex:column>
          
           <apex:column headerValue="Width">
          <apex:inputfield value="{!acc.Width__c}"/>
          </apex:column>

          </apex:pageblocktable>
        </apex:pageblock>
    </apex:form>
</apex:page>

I checked in inspect element i got a javascript error - 

SfdcCore.js:384 Visualforce Chart: Error loading configuration for chart 'jid0jid1pbjid3jid4': Unable to infer data model from result: result is not an Arrayb.resolve.b.provide.log @ SfdcCore.js:384 https://login.salesforce.com/17181/logo180.png Failed to load resource: the server responded with a status of 404 (Not Found)

Not sure wht tht means.

While debug i am getting in log the below - 
 
USER_DEBUG|[57]|DEBUG|@@@@(AggregateResult:{c=26, f=Bedding})



Regards
Sai KethuSai Kethu

I kind of getting same error, were you able to fix it?