我知道这听起来很奇怪但是这个演示http://jsbin.com/ixUzURUB/1/edit我无法将其转换为http://jsfiddle.net/jhb2L/我做错了什么?感谢。
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
var options = {
title: 'My Daily Activities'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
答案 0 :(得分:2)
当您添加外部资源时,JSFiddle会出现问题,而外部资源似乎并未以.js结尾。在路径中添加了?fake = .js并且它有效。还删除了JSFiddle添加的window.onload = function() {};
,现在它似乎正在运行。
答案 1 :(得分:1)
尝试粘贴此代码应该有效:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
var options = {
title: 'My Daily Activities'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
<div id="piechart" style="width: 900px; height: 500px;"></div>