如何将javascript变量分配给amcharts dataloader?

时间:2015-10-23 07:17:34

标签: javascript asp.net amcharts

我需要为amcharts dataloader分配一个javascript变量。但是以下代码不起作用(Graph不绘制)

AmCharts.ready(function () {

    var data = [{"employee_no": "101","Salary": "1000"},{"employee_no": "102","Salary": "1500"},{"employee_no": "103","Salary": "1100"},{"employee_no": "104","Salary": "1900"},{"employee_no": "105","Salary": "1200"},
    {"employee_no": "106","Salary": "1800"},{"employee_no": "107","Salary": "2000"},{"employee_no": "108","Salary": "1500"}];

    var chart = new AmCharts.AmSerialChart();
    chart.dataLoader = data;
    chart.categoryField = "employee_no";

    var graph = new AmCharts.AmGraph();
    graph.valueField = "Salary";
    graph.type = "line";
    graph.bullet = "round";
    graph.lineColor = "#8d1cc6";

    chart.addGraph(graph);

    chart.write('chartdiv');

    });

但是如果我使用下面的代码就行了。

  chart.dataLoader = {
            url: "MY_URL",
            postProcess: function (data, options) {
                if (data === null) {
                    data = [];
                    options.chart.addLabel("50%", "50%", "No Data Available");
                }
                return data;
            }
        };

上述代码有什么错误?我无法理解。

谢谢你

1 个答案:

答案 0 :(得分:0)

谢谢martynasma,你是对的

我必须使用chart.dataProvider代替chart.dataLoader

这解决了我的问题。我们只能将chart.dataLoader用于http请求。