我的任务是修复用户(IE8 和 IE9)抱怨的 Google Chart 问题。
基本上,我在前端的“标签”上有一个谷歌图表。我制作了前端的静态实例(将 HTML 保存在浏览器上)并将问题提炼为以下 HTML:
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type="text/javascript">
function ShowSection(strSectionName){
document.getElementById('TAB_TIME').style.backgroundColor='white';
document.getElementById('TAB_RESPONSES').style.backgroundColor='white';
document.getElementById('SECTION_TIME').style.display='none';
document.getElementById('SECTION_RESPONSES').style.display='none';
document.getElementById('TAB_'+ strSectionName).style.backgroundColor='lightblue';
document.getElementById('SECTION_'+ strSectionName).style.display='table-row';
}
</script>
</head>
<body style="margin:20px;" onLoad="ShowSection('RESPONSES');">
<table style="table-layout:fixed;width:1390px;" border="1" cellpadding="6" cellspacing="0">
<tr>
<td id="TAB_TIME" onClick="ShowSection('TIME');">TIME SERIES</td>
<td id="TAB_RESPONSES" onClick="ShowSection('RESPONSES');">RESPONSES</td>
</tr>
<tr id="SECTION_RESPONSES">
<td>Hello world</td>
</tr>
<tr id="SECTION_TIME" >
<td align="left" valign="top">
<div style="border:1px solid black;" id="CHART_SALES_OVER_TIME_WEEKLY"></div>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Dummy data', 'Sales'],
['1', 1],['2', 1],['3', 3],['4', 0]
]);
var options = {
height: 600,
width: 1370
};
var chart = new google.visualization.ColumnChart(document.getElementById('CHART_SALES_OVER_TIME_WEEKLY'));
chart.draw(data, options);
}
</script>
</td>
</tr>
</table>
</body>
</html>
因此,如果您启动它,您会看到它是两个选项卡(使用表格)的表示,通过 onLoad 隐藏和 onClick 在它们之间进行交换。
当您单击 TIME SERIES “选项卡”时,大多数浏览器上的一切都按预期工作,因为您会在 x 轴和 y 轴上看到数字;但是,在 IE8 和 IE9 中,轴上的数字不会加载。唯一的例外是将 body 标记更改为指向 TIME SERIES 选项卡 onLoad,即:
<body style="margin:20px;" onLoad="ShowSection('TIME');">
这样做会使 IE 加载数字。谁能向我解释 IE8 和 IE9 中的哪些不兼容导致 Google Chart 无法正确加载(即这里发生了什么!?),以及如何纠正它?