AmCharts.makeChart 和 new AmCharts.AmSerialChart() 有什么区别; [英] What is difference between AmCharts.makeChart and new AmCharts.AmSerialChart();
问题描述
一些 AmCharts demos 使用 AmCharts.makeChart代码>
Some AmCharts demos use AmCharts.makeChart
其他 AmCharts demos 使用 new AmCharts.AmSerialChart();
Other AmCharts demos use new AmCharts.AmSerialChart();
这两种方法有什么区别?
What is the difference in these two approaches?
推荐答案
使用 AmCharts.AmSerialChart()
你必须实例化你的所有组件(图形,轴,...),添加属性到这些对象,然后将它们分配给图表.这是创建图表的一种非常低效的方式,并且正如您在文档(您的第二个链接参考)中所见,已被弃用.
由于其版本 3 AmCharts
支持新的图表构造函数,您可以在其中以 JSON
格式指定所有属性.
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.
示例:
旧风格:
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");
});
新样式:(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"
},
});
这篇关于AmCharts.makeChart 和 new AmCharts.AmSerialChart() 有什么区别;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!