What is difference between AmCharts.makeChart and new AmCharts.AmSerialChart();

Using AmCharts.AmSerialChart() you have to instantiate all your components (graphs, axes, …), add properties to those objects and then assign them to the chart. This is a very inefficient way to create a chart, and, as you can see in the documentation (your 2nd link reference), deprecated.
Since its version 3 AmCharts supports the new chart constructor, where you can specify all properties in a JSON format.

Example:

old style:

AmCharts.ready(function () { 
                chart = new AmCharts.AmSerialChart();
                chart.pathToImages = "../amcharts/images/";
                chart.dataProvider = chartData;
                chart.categoryField = "date";

                // category axis               
                var categoryAxis = chart.categoryAxis;
                categoryAxis.parseDates = true;
                categoryAxis.minPeriod = "DD";

                // graph
                var graph = new AmCharts.AmGraph();
                graph1.valueField = "value";
                graph1.bullet = "round";
                chart.addGraph(graph1);

                var chartCursor = new AmCharts.ChartCursor();
                chartCursor.cursorPosition = "mouse";
                chart.addChartCursor(chartCursor);

                // WRITE
                chart.write("chartdiv");
});

new style: (doc)

AmCharts.makeChart("chartdiv", {
    type: "serial",
    pathToImages: "../amcharts/images/",
    dataProvider: chartData,
    categoryField: "date",
    categoryAxis: {
        parseDates: true,
        minPeriod: "ss"
    },
    graphs: [{
        valueField: "value",
        bullet: "round"
    }],
    chartCursor: {
        cursorPosition: "mouse"
    },
});

Leave a Comment