0

我知道这听起来很奇怪,但这个演示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);
  }
4

2 回答 2

2

当您添加似乎不以 .js 结尾的外部资源时,JSFiddle 会出现问题。在路径中添加了一个 ?fake=.js 并且它起作用了。还删除了window.onload = function() {};JSFiddle 添加的,现在它似乎正在工作。

http://jsfiddle.net/jhb2L/3/

于 2013-11-10T18:03:23.753 回答
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>
于 2013-11-10T17:54:11.497 回答