谷歌图表和HTA:脚本错误 https://www.gstatic.com/charts/loader.js



我想在HTA中动态使用谷歌图表。该代码作为 HTML 文件工作正常。但是当我在HTA中使用它时,我得到一个脚本错误:https://www.gstatic.com/charts/loader.js。

有人知道如何解决这个问题吗?是否可以在HTA(动态(中使用谷歌图表?

这是我在 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>

我发现了问题。我需要添加以下行:

<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"> 

相关内容

  • 没有找到相关文章

最新更新