On the server side, write a controller method that returns a List of objects, which can be your own Apex wrapper objects as in A Simple Charting Example, sObjects, or AggregateResult objects. The method is evaluated server-side, and the results serialized to JSON. On the client, these results are used directly by <apex:chart>, with no further opportunity for processing.
To illustrate this technique with sObjects, here is a simple controller that returns a list of Opportunities, and a bar chart for their amounts:
public class OppsController { // Get a set of Opportunities public ApexPages.StandardSetController setCon { get { if(setCon == null) { setCon = new ApexPages.StandardSetController(Database.getQueryLocator( [SELECT name, type, amount, closedate FROM Opportunity])); setCon.setPageSize(5); } return setCon; } set; } public List<Opportunity> getOpportunities() { return (List<Opportunity>) setCon.getRecords(); } }
<apex:page controller="OppsController"> <apex:chart data="{!Opportunities}" width="600" height="400"> <apex:axis type="Category" position="left" fields="Name" title="Opportunities"/> <apex:axis type="Numeric" position="bottom" fields="Amount" title="Amount"/> <apex:barSeries orientation="horizontal" axis="bottom" xField="Name" yField="Amount"/> </apex:chart> <apex:dataTable value="{!Opportunities}" var="opp"> <apex:column headerValue="Opportunity" value="{!opp.name}"/> <apex:column headerValue="Amount" value="{!opp.amount}"/> </apex:dataTable> </apex:page>