0

我认为 jQuery 对于使用 amCharts 不是强制性的。使用 jQuery 和 amCharts 有什么好处?

关于 amCharts 中使用的数据,是否有更“少编码”的方式将数据传递给它(而不是一遍又一遍地重复使用的列)?

var chartData = [{ country: "USA", visits: 4025, color: "#FF0F00" }, { country: "China", visits: 1882, color: "#FF6600" }, { etc....

最后,是否有一种更聪明的方法来构建图表,而不是一遍又一遍地定义每个 ONE(动态生成图表的问题)?

`

            // second graph                              
            graph = new AmCharts.AmGraph();
            graph.title = "North America";
            graph.labelText = "[[value]]";
            graph.valueField = "namerica";
            graph.type = "column";
            graph.lineAlpha = 0;
            graph.fillAlphas = 1;
            graph.lineColor = "#D8E0BD";
            chart.addGraph(graph);

            // thirdt graph              
            graph = new AmCharts.AmGraph();
            graph.title = "Asia-Pacific";
            graph.labelText = "[[value]]";
            graph.valueField = "asia";
            graph.type = "column";
            graph.lineAlpha = 0;
            graph.fillAlphas = 1;
            graph.lineColor = "#B3DBD4";
            chart.addGraph(graph);

            // fourth graph 
            graph = new AmCharts.AmGraph();
            graph.title = "Latin America";
            graph.labelText = "[[value]]";
            graph.valueField = "lamerica";
            graph.type = "column";
            graph.lineAlpha = 0;
            graph.fillAlphas = 1;
            graph.lineColor = "#69A55C";
            chart.addGraph(graph);

            // fifth graph 
            graph = new AmCharts.AmGraph();
            graph.title = "Middle-East";
            graph.labelText = "[[value]]";
            graph.valueField = "meast";
            graph.type = "column";
            graph.lineAlpha = 0;
            graph.fillAlphas = 1;
            graph.lineColor = "#B5B8D3";
            chart.addGraph(graph);

            // sixth graph  
            graph = new AmCharts.AmGraph();
            graph.title = "Africa";
            graph.labelText = "[[value]]";
            graph.valueField = "africa";
            graph.type = "column";
            graph.lineAlpha = 0;
            graph.fillAlphas = 1;
            graph.lineColor = "#F4E23B";
            chart.addGraph(graph);

`

谢谢

4

2 回答 2

0

听起来你是编程新手,或者你已经摆脱了只写简单的脚本。我建议开始阅读设计模式、一些 OOP 以及代码抽象的工作原理。

没有灵丹妙药可以实现您的要求,它可以通过一百万种方式完成。

现在回到您的问题,也许您可​​以创建一个函数来创建具有通用配置并使用传递的属性的图形。

function createGraph(title, valueField, color){
        var graph = new AmCharts.AmGraph();
        graph.title = title;
        graph.labelText = "[[value]]";
        graph.valueField = valueField;
        graph.type = "column";
        graph.lineAlpha = 0;
        graph.fillAlphas = 1;
        graph.lineColor = color;

}


var chart = Amcharts....;
var graphlist = [...];
for(int x = 0; x < graphlist; x++){
    chart.add(createGraph(graphList[x].title, graphList[x].valueField, graphList[x].color));
}

祝你好运!

于 2013-12-10T18:36:51.357 回答
0

我曾经使用 amcharts 最好的方法之一是使用数据加载器插件并从 CSV 加载数据或从任何 URL 加载数据。这可以减少代码,并且它也可以根据文件或 URL 非常频繁地更改。

数据加载器插件信息将在此处提供

于 2016-11-30T10:24:40.120 回答