如何将ajax成功数据传递给highcharts?

时间:2016-05-13 04:20:32

标签: javascript jquery ajax highcharts

为什么无法从data(str_borrowB)收到ajax? 我怎么写?

$(document).ready(function() {
    $.ajax({
        url: "json/stat01.json",
        type: "GET",
        dataType: "JSON",

        success: function(Jdata) {
            var dataLength = Jdata.length;
            var borrowB = "";
            var back = "";
            for (i = 0; i < dataLength; i++) {
                week = Jdata[i]["week"];
                flowNum = Jdata[i]["total"];
                borrowB = borrowB + Jdata[i]["borrow"] + ',';
                back = back + Jdata[i]["back"] + ',';
            }
            str_borrowB = borrowB.substr(0, (borrowB.length) - 1);
            str_backbook = back.substr(0, (back.length) - 1);

    //alert(str_borrowB) <--get value OK
        }
    })

它可以回复str_borrowB。   但我想将str_borrowB传递给jquery函数,它无法工作。

$('#container01').highcharts({
            chart: {
                type: 'column'
        },

        title: {
            text: 'picture'
        },

        xAxis: {
            categories: ['M', 'T', 'W', 'R', 'F', 'S', 'S']
        },

        yAxis: {
            allowDecimals: false,
            min: 0,
            title: {
                text: 'number'
            }
        },

        tooltip: {
            formatter: function() {
                return '<b>' + this.x + '</b><br/>' +
                    this.series.name + ': ' + this.y + 'number<br/>' +
                    'Total: ' + this.point.stackTotal + 'number';
            }
        },

        plotOptions: {
            column: {
                stacking: 'normal'
            }
        },

        series: [{
            name: 'borrow',
            //data: [3989, 12452, 13367, 12513, 12335, 9957, 6118],
            data: [str_borrowB],
        }, {
            name: 'back',
            data: [3915, 13188, 11590, 10606, 10318, 9051, 4549],
            //data: [str_backbook],
        }]
    });

0 个答案:

没有答案