0

我正在使用以下代码使用谷歌图表 api 创建折线图。

var array = [];
    ajaxPost(action, "getData", params, function(data) {
        var response = toObject(data).response;
        var chartData = new google.visualization.DataTable();

        for(var i = 0; i < response.occData.length; i++){
            chartData.addColumn("string",response.occData[i].reservationRowType);
        }

        new google.visualization.LineChart(document.getElementById('chart_div')).
        draw(chartData, {vAxes:[
        {title: 'Title 1', titleTextStyle: {color: '#FF0000'}}, // Left axis
        {title: 'Title 2', titleTextStyle: {color: '#FF0000'}} // Right axis
        ],series:[
            {targetAxisIndex:1},
            {targetAxisIndex:0}
        ],curveType: "function"});
});

我正在遍历 ajax 响应以将相关数据获取到 2D 数组,但是,这让我感到困惑!这是我的 ajax 响应。

{"response": {"status":true , "occData":[{"dayList":{1:9.0,2:6.0,3:4.0,4:4.0,5:3.0,6:3.0,7:3.0,8:3.0,9:3.0,10:7.0,11:7.0,12:6.0,13:4.0,14:4.0,15:4.0,16:4.0,17:3.0,18:3.0,19:4.0,20:6.0,21:7.0,22:6.0,23:7.0,24:6.0,25:5.0,26:8.0,27:9.0,28:7.0,29:8.0,30:8.0,31:5.0},"hotelCode":"BBH","month":"May","monthStartDate":"May-2012","orderSeq":11,"reservationRowType":"REV_OCC_PER","total":5.4,"year":"2012"},{"dayList":{1:52368.0,2:87239.0,3:126683.0,4:126683.0,5:147851.0,6:147851.0,7:147851.0,8:147851.0,9:147851.0,10:72566.0,11:66706.0,12:87915.0,13:110090.0,14:110090.0,15:110090.0,16:110090.0,17:147851.0,18:147851.0,19:126729.0,20:104461.0,21:95655.0,22:104562.0,23:88476.0,24:100402.0,25:111558.0,26:65367.0,27:61136.0,28:75780.0,29:70367.0,30:70367.0,31:111558.0},"hotelCode":"BBH","month":"May","monthStartDate":"May-2012","orderSeq":13,"reservationRowType":"ARR","total":96370.0,"year":"2012"}]}}

如何将此数据添加到二维数组或解析它以制作折线图!请帮我!

4

0 回答 0