你好,我正在尝试运行谷歌图表快速入门,但它不会在IE8中呈现。
我可以看到Google Chart确实创建了一些IE时髦的标记,但是没有显示任何内容。
该指南位于https://developers.google.com/chart/interactive/docs/quick_start上
是否需要一些额外的配置才能使其在IE8中工作?
发布于 2015-03-27 19:05:21
根据Google Charts文档,Internet Explorer 8和更早版本有时会出现问题,原因有两个:
为了让它正常工作,您需要添加vml名称空间并添加特定的css行为
<!--[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控件。”仅在允许阻止的内容之后,才会呈现饼图。
<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>
发布于 2015-03-27 19:18:39
从他们的图库(https://developers.google.com/chart/interactive/docs/gallery)中,IE8将重新使用VML:
这些图表基于纯HTML5/SVG技术(旧IE版本采用VML )
经过一些挖掘,看起来VML不只是工作,所以试着把它放在你的js的开头(或者可能更好,作为一个内联脚本放在你的html的顶部):
document.namespaces.add('v', 'urn:schemas-microsoft-com:vml', "#default#VML");这个人也有同样的问题:How do I get VML working in standards mode?
https://stackoverflow.com/questions/29299022
复制相似问题