单个页面上有多种类型的谷歌图表
Multiple types of Google Charts on single page
我试图在一个页面上获得多种类型的谷歌图表。饼图和日历图。当我尝试这样做时,我会得到以下错误来代替饼图:
You called the draw() method with the wrong type of data rather than a DataTable or DataView
如果我一次只做一个图表,错误就会消失。而且总是顶部的购物车显示相同的错误。我能说的最好的是因为数据是不同类型的。。所以我认为这与干扰变量有关。我为每个图表的数据添加了一个uniqe标识符,但我仍然会遇到问题。。。
以下是我的PHP的HTML输出:
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {
packages : [ 'corechart' ]
});
google.setOnLoadCallback(drawChart_testGraph);
function drawChart_testGraph() {
var data_testGraph = google.visualization.arrayToDataTable([
[ 'Department', 'Count' ], [ 'Accounting', 1 ], [ 'Lobby', 1 ],
[ 'Customer Apps', 1 ], [ 'PC Support', 0 ],
[ 'Collections', 0 ], [ 'Inventory', 1 ], [ 'Billing', 0 ],
[ 'Executive', 4 ], [ 'Customer Service', 0 ],
[ 'Sales and Marketing', 0 ], [ 'Product and Development', 1 ],
[ 'Materials Management', 0 ], [ 'Remittance', 0 ],
[ 'Support Services', 0 ], [ 'Indirect Distribution', 1 ],
[ 'Provisioning Support', 1 ], ]);
var options_testGraph = {
title : 'Usage by department',
backgroundColor : 'transparent',
is3D : 'false',
};
var chart_testGraph = new google.visualization.PieChart(document
.getElementById('testGraph'));
chart_testGraph.draw(data_testGraph, options_testGraph);
console.log(data_testGraph);
}
</script>
<div id='testGraph' style='width: 900px; height: 500px;'></div>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1.1', {
packages : [ 'calendar' ]
});
google.setOnLoadCallback(drawChart_testGraph2);
function drawChart_testGraph2() {
var dataTable_testGraph2 = new google.visualization.DataTable();
dataTable_testGraph2.addColumn({
type : 'date',
id : 'Department'
});
dataTable_testGraph2.addColumn({
type : 'number',
id : 'Count'
});
dataTable_testGraph2.addRows([ [ new Date('2014, 09, 18'), 1 ],
[ new Date('2014, 09, 17'), 1 ],
[ new Date('2014, 09, 15'), 6 ],
[ new Date('2014, 09, 13'), 1 ],
[ new Date('2014, 09, 12'), 2 ], ]);
var options_testGraph2 = {
title : 'Usage by department',
backgroundColor : 'white',
is3D : 'false',
};
var chart_testGraph2 = new google.visualization.Calendar(document
.getElementById('testGraph2'));
chart_testGraph2.draw(dataTable_testGraph2, options_testGraph2);
}
</script>
<div id='testGraph2' style='width: 900px; height: 500px;'></div>
</div>
有什么想法吗?
这不是加载谷歌软件包的正确方法,您尝试加载谷歌可视化软件包两次,所以第二次加载会覆盖第一次。您需要删除第二次加载,只需在第一个脚本中同时加载:(或同时加载两次)
google.load('visualization', '1', {
packages : [ 'corechart', 'calendar' ]
});
您可以支持旧版本。只需更改链接上js文件的版本号。
version':'1.1
至version':'1
类似:<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['corechart']}]}"></script>
相关文章:
- 使用谷歌地图API nearBysearch与多种类型
- 未捕获的类型错误:无法读取属性'fitBounds'谷歌地图(markrWithlabel js)中未定
- 如何在谷歌电子表格脚本中测试范围参数的类型
- 谷歌图表 - 地理图表“不兼容的数据表:错误:未知地址类型
- 谷歌地图API多段线创建失败;未捕获类型错误:数字不是函数;
- 未捕获的类型错误:无法读取属性'长度'未定义的谷歌地图V3
- 如何在面板中添加在两种类型的谷歌图表之间切换的按钮
- 谷歌URL缩短器API-未压缩类型错误:未定义不是一个函数
- 谷歌翻译,输入类型='文本'中的占位符文本
- 我可以在ebay中使用谷歌网页字体api或任何类型的自定义字体吗
- 使用输入类型=“0”改变Circle谷歌地图的半径;“范围”;
- 谷歌地图api 3使用覆盖选择地点的类型
- 谷歌地图数据类型抛出类型错误:can't将未定义转换为对象
- 如何在谷歌电子表格中检查单元格的类型
- 谷歌地图Javascript V3未捕获类型错误:无法读取属性'offsetWidth'为null
- 谷歌地图api v3未捕获类型错误:无法读取属性'offsetWidth'为null
- 谷歌地图和谷歌地点库中不同地点类型的不同图像
- 谷歌地图Javascript API“;未捕获类型异常-未定义不是函数“;
- 如何从谷歌地图中的坐标(纬度,长)获取地点类型
- Angular2 谷歌身份验证,按钮渲染上的类型错误