Google Charts和HTA:脚本错误https://www.gstatic.com/charts/loader.js

时间:2017-05-21 07:11:03

标签: javascript charts google-visualization hta

我想在HTA中动态使用Google Charts。该代码可以正常用作HTML文件。但是当我在HTA中使用它时,我在行上发现了一个脚本错误:https://www.gstatic.com/charts/loader.js

有人知道如何解决这个问题吗?是否可以在HTA(动态)中使用Google Charts?

我的HTML代码

<html>
 <head>
 <!--Load the AJAX API-->
 <script type="text/javascript"src="https://www.gstatic.com/charts/loader.js"></script>
 <script type="text/javascript">
  google.charts.load('current', {'packages':['corechart']});
  google.charts.setOnLoadCallback(drawChart);
  function drawChart() {
   var data = new google.visualization.DataTable();
   var x =   Math.floor((Math.random() * 10) + 1);
   data.addColumn('string', 'Topping');
   data.addColumn('number', 'Slices');
   data.addRows([
    ['Mushrooms', x],
    ['Onions', 1],
    ['Olives', 1],
    ['Zucchini', 1],
    ['Pepperoni', 2]
   ]);

   var options = {'title':'How Much Pizza I Ate Last Night',
   'width':1000,
   'height':750};
   var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
   chart.draw(data, options);
   }
  </script>
 </head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div">
</div>
<div>
 <button onclick="drawChart()">draw</button>
</div>
</body>
</html>

在我的HTA中,我只添加了HTA标签

<html>
 <head>
  <HTA:APPLICATION ID="Test Google Charts" 
       BORDER="thick" 
       BORDERSTYLE="complex"/>
  <!--Load the AJAX API-->
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> 
  <script type="text/javascript">
  google.charts.load('current', {'packages':['corechart']});
  google.charts.setOnLoadCallback(drawChart);
  function drawChart() {
   var data = new google.visualization.DataTable();
   var x =   Math.floor((Math.random() * 10) + 1);
   data.addColumn('string', 'Topping');
   data.addColumn('number', 'Slices');
   data.addRows([
    ['Mushrooms', x],
    ['Onions', 1],
    ['Olives', 1],
    ['Zucchini', 1],
    ['Pepperoni', 2]
   ]);

   var options = {'title':'How Much Pizza I Ate Last Night',
   'width':1000,
   'height':750};
   var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
   chart.draw(data, options);
   }
  </script>
 </head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div">
</div>
<div>
 <button onclick="drawChart()">draw</button>
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

我发现了问题。我需要添加这些行:

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=10"> 
标题中的

。所以一起

<HTA:APPLICATION ID="Test Google Charts" 
    BORDER="thick" 
    BORDERSTYLE="complex"/>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=10">