function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RitchiebRitchieb 

SOQL query for Pie chart - Cases Object

Hi All,

 

I am trying to build a simple pie chart with visual force / Apex. THe below code saves without errors but does not produce a chart. Can anyone point out what I am doing wrong?

 

Apex class;

 

This should be creating the pie chart data grouping cases by status.

 

public with sharing class CasesPieController {

public CasesPieController ()
{
}

public List<AggregateResult> getCasesByStatus()
{
    AggregateResult[] result = [SELECT COUNT(id) cnt, Status FROM Case GROUP BY Status];
    return result;
}



}

 

Visual Force page;

 

This should be a simple page with one block and one chart. The block displays but the chart doesnt at all.

 

<apex:page controller="CasesPieController" title="Pie Chart">
<apex:pageBlock >
<apex:pageBlockSection title="Cases by Status">
<apex:pageBlockSectionItem >
<apex:chart data="[!CasesByStatus]" height="400" width="380">
<apex:pieSeries labelField="id" dataField="cnt">
<apex:chartLabel display="rotate" field="cnt"/>
</apex:pieSeries>
</apex:chart>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>

 

Blank Chart

 

Thanks in advance if anyone is able to help :).

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

I see the problem now... you have square brackets "[ ]" instead of curly brackets "{ }" around your statement in the Visualforce page. Try changing that and see what happens.

All Answers

sfdcfoxsfdcfox

Use Firefox's or Chrome's Developer Console to see the "JavaScript debug messages" that explain why a chart fails to render. It's usually something wrong with the way the Visualforce Chart is configured (e.g. a name is wrong, invalid parameters, not enough parameters, the usual culprits of web scripting).

RitchiebRitchieb

Hi sfdcfox,

 

Thanks for the tip. After running the script debugger on IE and Chrome I get the below error on both;

 

This makes me think there is something wrong with the SOQL statement in the class, cant see what though.

 

  1. Visualforce Chart: Error loading configuration for chart 'jid0jid1jid2jid3jid4': Data retrieval function or object not found: '[!CasesByStatus]' SfdcCore.js:218
    1. Sfdc.provide.logSfdcCore.js:218

       

       

       

sfdcfoxsfdcfox

I see the problem now... you have square brackets "[ ]" instead of curly brackets "{ }" around your statement in the Visualforce page. Try changing that and see what happens.

This was selected as the best answer
RitchiebRitchieb

Great! Thanks for that, not sue why I didnt sopt that. Once your suggestion was fixed, all I needed was to change the fields being used. Great help, thanks!