HighCharts.js不是在IE8下呈现图表 [英] HighCharts.js is not rendering chart under IE8

查看:102
本文介绍了HighCharts.js不是在IE8下呈现图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用HighCharts和Python一起动态创建图表。所有工作正常,但是我得到不能读取IE8下的undefined 异常的属性0。不幸的是,我的客户也希望它能够在IE8下工作。所以继承了主函数的代码:

pre $函数generateChart(系列){
var chart = new Highcharts.Chart ({
图表:{
renderTo:'company_chart',
},
xAxis:{
类型:datetime,
},
yAxis:[{
title:{
text:T1,
},
},{
title:{
text: T2,
},
},
相反:true,
}],
plotOptions:{
series:{shadow:false},
列:{shadow:false,},
},
series:series
});
);

现在我的ajax请求会返回一些数据,并将其存储在像这样的变量中:

  chart_data = [
{
类型:样条线,
颜色:'#ff0000',
yAxis:0,
data:dataT1,
},
{
类型:列,
颜色:'#0000ff',
yAxis:1,
data:dataT2,
}
];

之后,我调用 generateChart(chart_data); 。变量 dataT1 dataT2 的格式很好,因为它适用于所有其他浏览器。例如 dataT1 可能如下所示:

  dataT1 = [[1325721600000 ,1.64],
[1325635200000,1.64],
[1325548800000,1.7],
[1325462400000,1.7],];

但IE8仍然会引发异常。任何想法如何解决这个问题?

解决方案

那些悬空的逗号导致Internet Explorer中的错误。



下面是一个例子:

 图表: {
renderTo:'company_chart',//< ---除掉那个逗号
},

Internet Explorer将对象文字末尾的逗号视为错误。实际上,您应该看到页面上的错误警告,但错误通常并不表示此实际根本原因。



edit —显然,IE8对此并不挑剔,虽然IE7是。



再次编辑然而,IE8将数据数组中最后一个逗号逗号解释为应该有一个额外的元素!换句话说:

  [1,2,3,]。长度

在Firefox / Chrome / Safari中为3,但在Internet Explorer中为 4 。当您尝试访问该元素时,浏览器会为您提供 undefined


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:

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:

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:

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?

解决方案

Those dangling commas are causing errors in Internet Explorer. Get rid of them.

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.

edit — well apparently IE8 is not picky about that, though IE7 is.

edit againHowever, IE8 interprets that last dangling comma in your data arrays as meaning that there should be an extra element! In other words:

 [1, 2, 3,].length

is 3 in Firefox/Chrome/Safari but it's 4 in Internet Explorer. When you try to access that element, the browser gives you undefined.

这篇关于HighCharts.js不是在IE8下呈现图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆