Pregunta

I have a hardcoded JSON object that I'm passing to google.visualization.DataTable() to create the data table object, but something appears to be going wrong. I get a JS error caught in the visualization api: "Uncaught TypeError: undefined is not a function". Here is the JSON data:

var jsonData = {
    cols: [
        {id: 'date', label: 'Sample Date', type: 'date'},
        {id: 'countervalue', label: 'Counter Value', type: 'number'}
    ],

    rows: [
        {c: [ {v: Date(2014, 4, 30, 10, 30, 0)}, {v: 2457.0} ] },
        {c: [ {v: Date(2014, 4, 30, 10, 30, 15)}, {v: 2458.0} ] },
        {c: [ {v: Date(2014, 4, 30, 10, 30, 30)}, {v: 2459.0} ] },
        {c: [ {v: Date(2014, 4, 30, 10, 30, 45)}, {v: 2452.0} ] },
        {c: [ {v: Date(2014, 4, 30, 10, 31, 0)}, {v: 2451.0} ] },
        {c: [ {v: Date(2014, 4, 30, 10, 31, 15)}, {v: 2443.0} ] },
        {c: [ {v: Date(2014, 4, 30, 10, 31, 30)}, {v: 2444.0} ] }
    ]
};

And this is where is appears to be blowing up:

var data = google.visualization.DataTable(jsonData);

Here's a JSFiddle of the solution: http://jsfiddle.net/jcaine04/3PJph/2/

¿Fue útil?

Solución

Code works fine, you just need to change:

var data = google.visualization.DataTable(jsonData);

To:

var data = new google.visualization.DataTable(jsonData);

Also, change in jsfiddle from onLoad to noWrap , if not drawChart() will not execute. Lastly, when you fix that it will throw you google error of: Pie chart should have a first column of type string×

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top