Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Visualization - TypeError: Cannot read property 'DataTable' of undefined [Chrome specific]

I am using Google Visualization Library my application was working correctly, I am unable to figure out how on chrome (specifically) this err starts coming up. Working fine in Firefox

function drawVisualization() {

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

// Declare columns
data.addColumn('date', 'Day');
data.addColumn('number', 'Person');

// Add data.
data.addRows(countArrayFinal);

// Create and draw the visualization.
new google.visualization.LineChart(document.getElementById('visualization')).draw(data, {
    title: 'Performance',
    width : 700,
    height : 300,
    vAxis : {
        maxValue : 4000
    }
});
}drawVisualization();
like image 890
Ashutosh Verma Avatar asked May 06 '14 09:05

Ashutosh Verma


People also ask

What is Google API in data visualization?

The Google Chart API is an extremely simple tool that lets you easily create a chart from some data and embed it in a webpage. You embed the data and formatting parameters in an HTTP request, and Google returns a PNG image of the chart.

How do you show no data available on Google chart?

Use noData() method to enable "No data" label: chart. noData().

What is arrayToDataTable?

arrayToDataTable()This helper function creates and populates a DataTable using a single call. Advantages: Very simple and readable code executed in the browser. You can either explicitly specify the data type of each column, or let Google Charts infer the type from the data passed in.


1 Answers

This error occurs because google visualization is not loaded.

Add this below the drawVisualization function:

google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawVisualization);

instead of

drawVisualization();
like image 200
davidkonrad Avatar answered Oct 03 '22 17:10

davidkonrad