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

匿名 (未验证) 提交于 2019-12-03 02:56:01

问题:

Some AmCharts demos use AmCharts.makeChart

Other AmCharts demos use new AmCharts.AmSerialChart();

What is the difference in these two approaches?

回答1:

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"     }, }); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!