javascript HighCharts.js 不渲染 IE8 下的图表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8790958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HighCharts.js is not rendering chart under IE8
提问by freakish
I am using HighCharts together with Python to dynamically create charts. All works fine, however I get cannot read property "0" of undefined
exception under IE8. Unfortunetly my client want it to work under IE8 as well. So heres the code of the main function:
我使用 HighCharts 和 Python 来动态创建图表。一切正常,但是我cannot read property "0" of undefined
在 IE8 下出现异常。不幸的是,我的客户希望它也能在 IE8 下工作。所以继承人的主要功能的代码:
function generateChart(series) {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'company_chart',
},
xAxis: {
type: "datetime",
},
yAxis: [{
title: {
text: "T1",
},
},{
title: {
text: "T2",
},
},
opposite: true,
}],
plotOptions: {
series: { shadow: false },
column: { shadow: false, },
},
series: series
});
);
Now my ajax request returns some data and I store it in the variable like this:
现在我的 ajax 请求返回一些数据,并将其存储在变量中,如下所示:
chart_data = [
{
type: "spline",
color: '#ff0000',
yAxis: 0,
data: dataT1,
},
{
type: "column",
color: '#0000ff',
yAxis: 1,
data: dataT2,
}
];
After that I call generateChart(chart_data);
. The format of variables dataT1
and dataT2
is fine, since it works under every other browser. For example dataT1
may look like this:
之后我打电话给generateChart(chart_data);
。变量的格式dataT1
和dataT2
很好,因为它可以在所有其他浏览器下运行。例如dataT1
可能看起来像这样:
dataT1 = [ [1325721600000,1.64],
[1325635200000,1.64],
[1325548800000,1.7],
[1325462400000,1.7],];
But still the exception is thrown under IE8. Any ideas how to fix this?
但是在IE8下仍然抛出异常。任何想法如何解决这一问题?
回答by Pointy
Those dangling commas are causing errors in Internet Explorer. Get rid of them.
那些悬空的逗号会导致 Internet Explorer 出现错误。摆脱他们。
Here's an example:
下面是一个例子:
chart: {
renderTo: 'company_chart', // <--- get rid of that comma
},
Internet Explorer considers a comma at the end of an object literal like that to be an error. You should in fact be seeing the "Errors on page" warning, but the error is usually something that does not indicate this actual root cause.
Internet Explorer 将此类对象字面量末尾的逗号视为错误。您实际上应该看到“页面上的错误”警告,但该错误通常并不表明此实际根本原因。
edit— well apparently IE8 is not picky about that, though IE7 is.
编辑- 显然 IE8 对此并不挑剔,尽管 IE7 是。
edit again— However, IE8 interprets that last dangling comma in your data arrays as meaning that there should be an extra element! In other words:
再次编辑——然而,IE8 将数据数组中最后一个悬空的逗号解释为意味着应该有一个额外的元素!换句话说:
[1, 2, 3,].length
is 3 in Firefox/Chrome/Safari but it's 4in Internet Explorer. When you try to access that element, the browser gives you undefined
.
在 Firefox/Chrome/Safari 中为 3,但在 Internet Explorer 中为4。当您尝试访问该元素时,浏览器会为您提供undefined
.