0

I have two fields on my Account page, one is a Roll Up Sum and one is a Formula field that I'd like to push into a bar chart. They are both of currency format. Do I need to use a controller class to get the two fields as data? All examples I see are based on queries of series of objects, or hard coded examples. Thanks for assisting.

Draft page:

<apex:page standardController="Account" >
<script>

var dataArray = new Array();
dataArray.push({'data1':{!Account.NumberofEmployees},'name':'EMP'});
dataArray.push({'data1':{!Account.X2014_Net_Revenue__c},'name':'LOCS'});

</script>

<apex:chart data="dataArray" height="200px" width="200px">
<apex:legend position="left"/>
<apex:axis type="Numeric" position="left" title="YoY" grid="true"
    fields="data1" dashSize="2">
    <apex:chartLabel />
</apex:axis>
<apex:axis type="Category" position="bottom" fields="name" title="Stacked Bars">
    <apex:chartLabel rotate="315"/>
</apex:axis>
<apex:barSeries orientation="vertical" axis="left" stacked="true"
    xField="name" yField="data1" title="2013,2014"/></apex:chart>
</apex:page>

1 Answer 1

1

You can use Javascript on the page to populate the charts data array. Something like this:

<apex:page standardController="Account" >
<script>
// Build the chart data array in JavaScript
var dataArray = new Array();
dataArray.push({'data1':{!Account.NumberofEmployees},'name':'EMP'});
dataArray.push({'data1':{!Account.NumberofLocations__c},'name':'LOCS'});
// 
</script>

<apex:chart data="dataArray" height="200px" width="200px">
<apex:legend position="left"/>
<apex:axis type="Numeric" position="left" title="Demo" grid="true"
    fields="data1" dashSize="2">
    <apex:chartLabel />
</apex:axis>
<apex:axis type="Category" position="bottom" fields="name" title="Stacked Bars">
    <apex:chartLabel rotate="315"/>
</apex:axis>
<apex:barSeries orientation="vertical" axis="left" stacked="true"
    xField="name" yField="data1" title="EMP,LOCS"/></apex:chart>
</apex:page>

Just update the data array with the field names you want to use, and the labels as well.

5
  • Thanks., but with a quick update putting in my fields I get no result if I plug it into an Account page. Nothing displays. I also tried using a standard fields.
    – jaw999
    Apr 1, 2015 at 12:48
  • Are you getting an error? Check your javascript console as well. Could you post your version of the page?
    – JimRae
    Apr 1, 2015 at 13:07
  • java script console shows error: 2https://login.salesforce.com/17181/logo180.png Failed to load resource: the server responded with a status of 404 (Not Found) - i am in a sandbox
    – jaw999
    Apr 1, 2015 at 13:47
  • then further: Uncaught SyntaxError: Unexpected token E servlet.Integration:1 Uncaught SyntaxError: Unexpected token E
    – jaw999
    Apr 1, 2015 at 13:48
  • I don't know what the issue is in the sandbox but this seems to work fine in my prod instance. thanks
    – jaw999
    Apr 1, 2015 at 17:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .