最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - HighCharts.js is not rendering chart under IE8 - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Mar 2, 2013 at 15:33 Josh Unger 7,1637 gold badges37 silver badges55 bronze badges asked Jan 9, 2012 at 15:40 freakishfreakish 56.5k12 gold badges137 silver badges177 bronze badges 2
  • Actually I'm using HighStock (but here I use only HighCharts) and the exception is thrown in highstock.js script. It seems that it is trying to read chart_data[0].data[0] and it throws the exception. I can't say for sure, because I used minified version. The strange thing is that when I debug it chart_data[0].data is null but chart_data[1].data is not. But all asigments are fine (they work under other browsers). – freakish Commented Jan 9, 2012 at 15:54
  • See my answer update. The problem is with the dangling commas in your data array definitions. – Pointy Commented Jan 9, 2012 at 15:55
Add a comment  | 

1 Answer 1

Reset to default 18

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.

发布评论

评论列表(0)

  1. 暂无评论