Have a graph setup with some simple data coming from a controller.Below is the code for the visualforce page.
<apex:page readonly="true">
<apex:tabPanel switchType="server" id="panel">
<apex:tab label="Pie chart" id="tab1">
<script>
var pieData = [{'data1':100, 'name':'Alice'}, {'data1':30, 'name':'Bob'}, {'data1':55, 'name':'Carl'}, {'data1':60, 'name':'Dan'}];
</script>
<apex:chart data="pieData" height="200px" width="200px">
<apex:pieSeries labelField="name" dataField="data1"/>
</apex:chart>
</apex:tab>
<apex:tab label="Line chart" id="tab2">
<script>
var barData = [{'data':100, 'label':'UK'}, {'data':30, 'label':'France'}, {'data':55, 'label':'Spain'}, {'data':60, 'label':'Germany'}];
</script>
<apex:chart data="barData" height="200px" width="300px">
<apex:legend position="left"/>
<apex:axis type="Numeric" position="left" title="Nos Leads" grid="true" fields="data" minimum="0">
</apex:axis>
<apex:axis type="Category" position="bottom" fields="label" title="Country">
<apex:chartLabel rotate="315"/>
</apex:axis>
<apex:barSeries orientation="vertical" axis="left" xField="label" yField="data"/>
</apex:chart>
</apex:tab>
</apex:tabPanel>
</apex:page>
Can anyone please help me out with the code as to dynamically pass values instead of passing values in script ?
Best Answer
Below is some code that I posted as an answer to this Salesforce Visualforce Bar Chart problem question that uses the "controller method reference"
data
option. For naming you are using in your Visualforce, in the class changev
todata
andn
toname
.To support multiple charts, you would need to add multiple methods that return different data.