function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Marcela SanchezMarcela Sanchez 

How can I implement amcharts in a visualforce page?

I'm trying to implement the charts in a Visualforce page, but even the samples show only white space.
Best Answer chosen by Marcela Sanchez
Rakesh51Rakesh51
Example :- ​show the count of the records based on the created date-month(monthly) on a bar chart using Visualforce charting. 
 
public with sharing class ChartController {

    public class Month {
        public Integer year {get; set;}
        public Integer month {get; set;}
        public Integer count {get; set;}
        public String yearMonth {get; set; }
        Month(Integer year, Integer month, Integer count) {
            this.year = year;
            this.month = month;
            this.count = count;
            this.yearMonth = year + '/' + month;
        }
    }

    public Month[] getMonths() {
        Month[] months = new Month[] {};
        for (AggregateResult ar : [
                select
                        CALENDAR_YEAR(CreatedDate) y,
                        CALENDAR_MONTH(CreatedDate) m,
                        COUNT(Id) c
                from Contact
                group by CALENDAR_YEAR(CreatedDate), CALENDAR_MONTH(CreatedDate)
                order by CALENDAR_YEAR(CreatedDate), CALENDAR_MONTH(CreatedDate)
                ]) {
            months.add(new Month(
                    (Integer) ar.get('y'),
                    (Integer) ar.get('m'),
                    (Integer) ar.get('c')
                    ));
        }
        return months;
    }
}

and the corresponding chart page:
 
<apex:page controller="ChartController">
    <apex:chart height="400" width="400" data="{!months}">
        <apex:axis type="Numeric" position="left" fields="count"
                title="Record Count"/>
        <apex:axis type="Category" position="bottom" fields="yearMonth"
                title="Year/Month"/>
        <apex:barSeries orientation="vertical" axis="left"
                xField="yearMonth" yField="count"/>
    </apex:chart>
</apex:page>

and an example of the output produced:

User-added image

Some Apex code should be added to fill in the months that have no data.