收到一系列有关在 IE7 中运行 JavaScript 的兼容性问题的问题。我正在使用 jqplot 生成图形,它在 Chrome 和 IE8 中运行良好,但在 IE7 中不起作用。
为了诊断,我只需运行最简单的代码 $.jqplot('chart1', s1)
并且它可以在 IE7 中运行。所以我认为问题在于所有选项(除了图例)。有人能给我一些建议吗? IE7 只接受某种类型的语法吗?
代码和 Demo :
<div id="chart1" style="margin-top:20px; margin-left:20px; width:650px; height:400px;"></div>
<!--[if lt IE 9]>
<script src="http://www.prioritymarketers.com/jqplot/src/excanvas.min.js"></script>
<![endif]-->
<script>
$.jqplot.config.enablePlugins = true;
var ms= 2
var s1 =[[5.0, 23.0, 131.0, 779.0, 4667.0, 27995.0, 167963.0, 1007771.0, 6046619.0, 36279707.0], [13.0, 85.0, 517.0, 3109.0, 18661.0, 111973.0, 671845.0, 4031077.0, 24186469.0, 145118821.0]]
L = [{label: 'Stage 1'}];
var i = 2
while (i <= ms) {
L.push({label: 'Stage' + i});
i++;
}
$.jqplot('chart1', s1, {
seriesDefaults: {
showMarker: false,
pointLabels: {
show: false
},
},
series: L,
axes: {
xaxis: {
label: 'Time units',
pad: 0,
},
yaxis: {
label: 'Number of individuals',
labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
pad: 0
}
},
legend: {
show: true,
location: 'nw',
placement: 'inside',
fontSize: '11px'
}
})
</script>
最佳答案
我注意到 IE 不太喜欢在一组选项的最后一个元素后面加逗号。
示例:
这个:
seriesDefaults: {
showMarker: false,
pointLabels: {
show: false
},
},
会变成:
seriesDefaults: {
showMarker: false,
pointLabels: {
show: false
}},
细微的差别,但它可能会也可能不会解决您的问题。
尝试将绘图函数更改为:
$.jqplot('chart1', s1, {
seriesDefaults: {
showMarker: false,
pointLabels: {
show: false
}
},
series: L,
axes: {
xaxis: {
label: 'Time units',
pad: 0
},
yaxis: {
label: 'Number of individuals',
labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
pad: 0
}
},
legend: {
show: true,
location: 'nw',
placement: 'inside',
fontSize: '11px'
}
})
另外,上次我使用 excanvas 时,我最终不得不确保它是最新版本。
关于javascript - jqplot 在 IE7 中运行不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12219554/