Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单页上有多种类型的谷歌图表_Javascript_Html_Google Visualization - Fatal编程技术网

Javascript 单页上有多种类型的谷歌图表

Javascript 单页上有多种类型的谷歌图表,javascript,html,google-visualization,Javascript,Html,Google Visualization,我试图在一个页面上获得多种类型的谷歌图表。饼图和日历图。当我尝试执行此操作时,会出现以下错误,而不是饼图: You called the draw() method with the wrong type of data rather than a DataTable or DataView 如果我一次只做一张图表,错误就会消失。而且总是顶部的购物车显示相同的错误。我能说的最好的是,因为数据的类型不同。。所以我认为这与干扰变量有关。我在每个图表的数据中添加了一个uniqe标识符,但仍然存在问题

我试图在一个页面上获得多种类型的谷歌图表。饼图和日历图。当我尝试执行此操作时,会出现以下错误,而不是饼图:

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>

load('visualization','1','{
软件包:['corechart']
});
setOnLoadCallback(drawChart\u testGraph);
函数drawChart_testGraph(){
var data_testGraph=google.visualization.arrayToDataTable([
[“部门”、“盘点”]、[“会计”,1]、“大厅”,1],
[“客户应用程序”,1],“PC支持”,0],
[“收款”,0],“库存”,1],“账单”,0],
[“高管”,4],“客户服务”,0],
[“销售和营销”,0],“产品和开发”,1],
[“物料管理”,0],“汇款”,0],
[“支持服务”,0],“间接分发”,1],
[‘资源调配支持’,1],]);
变量选项\u测试图={
标题:“按部门使用”,
背景色:“透明”,
is3D:'假',
};
var chart\u testGraph=新的google.visualization.PieChart(文档
.getElementById('testGraph');
绘制(数据图、选项图);
日志(数据测试图);
}
load('visualization','1.1','{
套餐:[“日历”]
});
setOnLoadCallback(drawChart\u testGraph2);
函数绘图图\u testGraph2(){
var dataTable_testGraph2=新的google.visualization.dataTable();
dataTable_testGraph2.addColumn({
键入:“日期”,
id:‘部门’
});
dataTable_testGraph2.addColumn({
键入:“编号”,
id:'计数'
});
dataTable_testGraph2.addRows([[新日期('2014,09,18'),1],
[新日期('2014,09,17'),1],
[新日期('2014,09,15'),6],
[新日期('2014年9月13日'),1],
[新日期('2014,09,12'),2],]);
变量选项\u测试图2={
标题:“按部门使用”,
背景颜色:“白色”,
is3D:'假',
};
var chart\u testGraph2=新的google.visualization.Calendar(文档
.getElementById('testGraph2');
图表_testGraph2.draw(数据表_testGraph2,选项_testGraph2);
}

有什么想法吗?

这不是加载google软件包的正确方法,您尝试加载google可视化软件包2次,因此第二次加载会覆盖第一次加载。您需要删除第二次加载,然后在第一个脚本中同时加载两次:(或同时加载两次)


你可以支持旧版本。只需更改链接上js文件的版本号

version':'1.1
version':'1


比如:

您只需在页面中添加一次
。@我不知道,这只是我的PHP脚本中的逻辑。这是我将来要做的事情,但我测试了它,它并没有影响问题。这很有趣,我在YouTube分析上也遇到了同样的问题!向那里的开发团队大声喊道。我创建了一个示例,表明只要您以这种方式使用包,代码就可以工作。谢谢!既然你指出了这一点,我知道这句话的真正含义:)谢谢你解决了fiddle@robertno问题。这本来是我回答的一部分,但你抢先了我一步:)
google.load('visualization', '1', {
    packages : [ 'corechart', 'calendar' ]
});