You need to sign in to do that
Don't have an account?
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>
Thanks in advance if anyone is able to help :).
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
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).
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.
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.
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!