Error Google LineChart with proper (?) JSON format

蹲街弑〆低调 提交于 2019-12-25 02:47:08

问题


Sorry all!! I know there are several (many) post regarding JSON and google api. I read them all and tried fixing the problem for several days. I am going to explode if I have to clear my browsing history, again, to start with a "fresh" mind... I could really use some help. Any and all help would be greatly appreciated.

Console error prints : "TypeError: b[le] is not a function"

Here is my function:

function timeline() {
    $.post('NewQuery.php', function ( data ) {
        alert (data);
        var data = new google.visualization.DataTable(JSON.parse(data));  

        var view = new google.visualization.DataView(data)
        view.setColumns ([0,2]) 

        chart = new google.visualization.LineChart(document.getElementById('chart2'));
        chart.draw(view);   
    });
}

Here is the JSON object that is 'alerted'- I formatted it to make it more legible.

{
    "cols":[
        {"label":"Dia","type":"date"},
        {"label":"Fruta","type":"string"},
        {"label":"CostoTotal","type":"number"}
    ],
    "rows":[
        {"c":[{"v":"Dia(2014, 3, 9)"},{"v":"Kiwis"},{"v":2628}]},
        {"c":[{"v":"Dia(2014, 3, 18)"},{"v":"Cerezos"},{"v":3200841}]},
        {"c":[{"v":"Dia(2014, 3, 23)"},{"v":"Peras"},{"v":113696}]},
        {"c":[{"v":"Dia(2014, 3, 1)"},{"v":"Cerezos"},{"v":4294967295}]}
    ]
}

回答1:


The problem is with your date strings, they should use the word "Date", not "Dia". This:

"Dia(2014, 3, 9)"

should be this:

"Date(2014, 3, 9)"


来源:https://stackoverflow.com/questions/23370474/error-google-linechart-with-proper-json-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!