我正在尝试为我的网页创建一个信息中心,但我无法实例化信息中心。
var dashboard = new google.visualization.Dashboard(document.getElementById("marketareas_div"));
和apicall:
<script type="text/javascript"
src='https://www.google.com/jsapi?autoload={"modules":[{"name":"visualization","version":"1.1","packages":["corechart"]}]}'/>
问题:“google.visualization.Dashboard不是构造函数”。
答案 0 :(得分:3)
首先需要关闭该脚本标记,否则页面会在某些浏览器中中断。
问题似乎是当您使用google包核心图包含脚本时没有Dashboard对象。将其更改为包含仪表板的控件。
更多信息: http://code.google.com/intl/sv-SE/apis/chart/interactive/docs/gallery/controls.html
答案 1 :(得分:2)
您的API是否已正确加载?
查看Google的documentation,您的自动加载网址不正确,应进行编码:
此:
{ “模块”:[{ “名称”: “搜索”, “版本”: “1.0”, “语言”: “EN”},{ “名称”: “映射”, “版本”:“2 .X “},{” 名称 “:” 元素”, “版本”: “1.0”, “包”:[ “本地搜索”]}]}
成为这个:
%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
这样称呼:
<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>
他们实际上不建议使用这种方式进行加载。
警告!此高级功能可能难以实施, 视具体情况而定。因此,我们建议您 考虑仅在减少的特定情况下自动加载 延迟是至关重要的。
尝试使用更简单的加载,例如:
<script type="text/javascript">
google.load("visualization", "1.1");
...
</script>