Apex Class:
public class LineChartController {
// Return a list of data points for a chart
public List<DataWrapper> getData() {
return LineChartController.getChartData();
}
public static List<DataWrapper> getChartData() {
List<DataWrapper> dataWrap= new List<DataWrapper>();
dataWrap.add(new DataWrapper('JAN', 30));
dataWrap.add(new DataWrapper('FEB', 44));
dataWrap.add(new DataWrapper('MAR', 25));
return dataWrap;
}
// Wrapper class
public class DataWrapper {
public String name { get; set; }
public decimal data { get; set; }
public dataWrapper(String name, integer value) {
this.name = name;
this.data = value;
}
}
}
public class LineChartController {
// Return a list of data points for a chart
public List<DataWrapper> getData() {
return LineChartController.getChartData();
}
public static List<DataWrapper> getChartData() {
List<DataWrapper> dataWrap= new List<DataWrapper>();
dataWrap.add(new DataWrapper('JAN', 30));
dataWrap.add(new DataWrapper('FEB', 44));
dataWrap.add(new DataWrapper('MAR', 25));
return dataWrap;
}
// Wrapper class
public class DataWrapper {
public String name { get; set; }
public decimal data { get; set; }
public dataWrapper(String name, integer value) {
this.name = name;
this.data = value;
}
}
}
Visualforce Page :
<apex:page controller="LineChartController">
<apex:chart height="400" width="700" data="{!data}">
<apex:axis type="Numeric" position="left" fields="data"
title="Opportunities Closed" grid="true"/>
<apex:axis type="Category" position="bottom" fields="name"
title="Month of the Year">
</apex:axis>
<apex:lineSeries axis="left" fill="true" xField="name" yField="data"
markerType="cross" markerSize="4" markerFill="#FF0000"/>
</apex:chart>
</apex:page>
Output :
No comments:
Post a Comment