1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Visualforceでエリアグラフ表示

Last updated at Posted at 2012-12-26

Winter'13でグラフを表示するためのapex:chartが正式にリリースされました。

これを使用してエリアグラフを表示することができます。

Apex
public with sharing class Chart_AreaSeries {
    
    public List<Data> getData() {
        return Chart_AreaSeries.getChartData();
    }
    
    @RemoteAction
    public static List<Data> getRemoteData() {
        return Chart_AreaSeries.getChartData();
    }
    
    public static List<Data> getChartData() {
        List<Data> data = new List<Data>();
        data.add(new Data('Jan', 30, 90, 55));
        data.add(new Data('Feb', 44, 15, 65));
        data.add(new Data('Mar', 25, 32, 75));
        data.add(new Data('Apr', 74, 28, 85));
        data.add(new Data('May', 65, 51, 95));
        data.add(new Data('Jun', 33, 45, 99));
        data.add(new Data('Jul', 92, 82, 30));
        data.add(new Data('Aug', 87, 73, 45));
        data.add(new Data('Sep', 34, 65, 55));
        data.add(new Data('Oct', 78, 66, 56));
        data.add(new Data('Nov', 80, 67, 53));
        data.add(new Data('Dec', 17, 70, 70));
        return data;
    }
    
    public class Data {
        public String name { get; set; }
        public Integer data1 { get; set; }
        public Integer data2 { get; set; }
        public Integer data3 { get; set; }
        public Data(String name, Integer data1, Integer data2, Integer data3) {
            this.name = name;
            this.data1 = data1;
            this.data2 = data2;
            this.data3 = data3;
        }
    }
}
Visualforce
<apex:page controller="Chart_AreaSeries">
    <apex:chart height="400" width="700" animate="true" legend="true" data="{!data}">
        <apex:legend position="left"/>
        <apex:axis type="Numeric" position="left" fields="data1,data2,data3"  title="Closed Won" grid="true">
            <apex:chartLabel />
        </apex:axis>
        <apex:axis type="Category" position="bottom" fields="name"  title="Month of the Year">
            <apex:chartLabel rotate="315"/>
        </apex:axis>
        <apex:areaSeries axis="left" xField="name" yField="data1,data2,data3" tips="true"/>
    </apex:chart>
</apex:page>
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?