首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >谷歌图表-“快速入门Hello World”未在IE8中呈现

谷歌图表-“快速入门Hello World”未在IE8中呈现
EN

Stack Overflow用户
提问于 2015-03-27 18:54:30
回答 2查看 281关注 0票数 0

你好,我正在尝试运行谷歌图表快速入门,但它不会在IE8中呈现。

我可以看到Google Chart确实创建了一些IE时髦的标记,但是没有显示任何内容。

该指南位于https://developers.google.com/chart/interactive/docs/quick_start

是否需要一些额外的配置才能使其在IE8中工作?

EN

回答 2

Stack Overflow用户

发布于 2015-03-27 19:05:21

根据Google Charts文档,Internet Explorer 8和更早版本有时会出现问题,原因有两个:

  1. IE8不支持SVG,因此图表故障转移到VML,这是更有限的。
  2. IE8的JavaScript不允许在列表中使用尾随逗号。

为了让它正常工作,您需要添加vml名称空间并添加特定的css行为

代码语言:javascript
复制
<!--[if lte IE 8 ]>
<script type="text/javascript">
    document.namespaces.add('vml', 'urn:schemas-microsoft-com:vml');
    document.createStyleSheet().cssText =
    'vml\\:fill, vml\\:path, vml\\:shape, vml\\:stroke' +
    '{ behavior:url(#default#VML); display: inline-block; } ';
</script>
<![endif]-->

我已经仔细检查过了,下面的例子在Windows7的IE8中运行。但是,它最初确实显示了警告“为了保护您的安全,Internet Explorer已限制此网页运行可能访问您的计算机的脚本或ActiveX控件。”仅在允许阻止的内容之后,才会呈现饼图。

代码语言:javascript
复制
<html>

<head>
  <!--Load the AJAX API-->
  <!--[if lte IE 8 ]>
	<script type="text/javascript">
		document.namespaces.add('vml', 'urn:schemas-microsoft-com:vml');
		document.createStyleSheet().cssText =
		'vml\\:fill, vml\\:path, vml\\:shape, vml\\:stroke' +
		'{ behavior:url(#default#VML); display: inline-block; } ';
	</script>
	<![endif]-->
  <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  <script type="text/javascript">
    // Load the Visualization API and the piechart package.
    google.load('visualization', '1.0', {
      'packages': ['corechart']
    });

     // Set a callback to run when the Google Visualization API is loaded.
    google.setOnLoadCallback(drawChart);

     // Callback that creates and populates a data table,
     // instantiates the pie chart, passes in the data and
     // draws it.
    function drawChart() {

      // Create the data table.
      var data = new google.visualization.DataTable();
      data.addColumn('string', 'Topping');
      data.addColumn('number', 'Slices');
      data.addRows([
        ['Mushrooms', 3],
        ['Onions', 1],
        ['Olives', 1],
        ['Zucchini', 1],
        ['Pepperoni', 2]
      ]);

      // Set chart options
      var options = {
        'title': 'How Much Pizza I Ate Last Night',
        'width': 400,
        'height': 300
      };

      // Instantiate and draw our chart, passing in some options.
      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>
</body>

</html>

票数 0
EN

Stack Overflow用户

发布于 2015-03-27 19:18:39

从他们的图库(https://developers.google.com/chart/interactive/docs/gallery)中,IE8将重新使用VML:

这些图表基于纯HTML5/SVG技术(旧IE版本采用VML )

经过一些挖掘,看起来VML不只是工作,所以试着把它放在你的js的开头(或者可能更好,作为一个内联脚本放在你的html的顶部):

代码语言:javascript
复制
document.namespaces.add('v', 'urn:schemas-microsoft-com:vml', "#default#VML");

这个人也有同样的问题:How do I get VML working in standards mode?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29299022

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档