SolidALb
SolidALb

Reputation: 130

Google charts visualization instantiateproblem Dashboard

Im trying to create a Dashboard for my webpage but I cant instantiate the Dashboard.

var dashboard = new google.visualization.Dashboard(document.getElementById("marketareas_div"));

and the apicall:

<script type="text/javascript"
src='https://www.google.com/jsapi?autoload={"modules":[{"name":"visualization","version":"1.1","packages":["corechart"]}]}'/>

Problem: "google.visualization.Dashboard is not a constructor".

Upvotes: 2

Views: 2963

Answers (2)

Dean
Dean

Reputation: 106

First of you need to close that script-tag otherwise the page will break in some browsers.

The problem seems to be that there is no Dashboard-object when you include the script with package corechart from google. Change it to controls which includes Dashboard.

More info: http://code.google.com/intl/sv-SE/apis/chart/interactive/docs/gallery/controls.html

Upvotes: 3

Didier Ghys
Didier Ghys

Reputation: 30666

Is your API correctly loaded ?

Looking at the google's documentation, your auto-loading url is not correct, it should be encoded:

This:

{"modules":[{"name":"search","version":"1.0","language":"en"},{"name":"maps","version":"2.x"},{"name":"elements","version":"1.0","packages":["localsearch"]}]}

becomes this:

%7B%22modules%22%3A%5B%7B%22name%22%3A%22search%22%2C%22version%22%3A%221.0%22%2C%22language%22%3A%22en%22%7D%2C%7B%22name%22%3A%22maps%22%2C%22version%22%3A%222.X%22%7D%2C%7B%22name%22%3A%22elements%22%2C%22version%22%3A%221.0%22%2C%22packages%22%3A%5B%22localsearch%22%5D%7D%5D%7D

to be called like this:

<script src="https://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22search%22%2C%22version%22%3A%221.0%22%2C%22language%22%3A%22en%22%7D%2C%7B%22name%22%3A%22maps%22%2C%22version%22%3A%222.X%22%7D%2C%7B%22name%22%3A%22elements%22%2C%22version%22%3A%221.0%22%2C%22packages%22%3A%5B%22localsearch%22%5D%7D%5D%7D&key=INSERT-YOUR-KEY"></script>


They actually don't recommend using this way for loading.

Warning! This advanced feature can be difficult to implement, depending on the exact situation. Therefore, we recommend that you consider auto-loading only in specific instances where reducing latency is crucial.

Try using a more simple loading like:

<script type="text/javascript">
    google.load("visualization", "1.1");
    ...
</script>

Upvotes: 2

Related Questions