javascript - 未捕获的类型错误 : Cannot read property '0' of undefined javascript error and with highcharts

标签 javascript jquery highcharts

直接到我正在下载图表的 PDF 时,我在浏览器控制台上遇到上述异常,显示“未捕获的类型错误:无法读取未定义的属性“0””。

不知道为什么会出现此错误。我还有其他报告,下载效果很好。但有时我会遇到这个问题。我正在运行的代码如下。

我正是在这一行遇到问题 window[theSelectedChart].exportChart({

谁能帮帮我。提前致谢。

if(theSelectedChart == 'somechart') {
   if(Shortform.chartType == 'bubble'){
        var maxDays = Math.max.apply(Math, Shortform.activeDays);
        var minDays = Math.min.apply(Math, Shortform.activeDays);
        window[theSelectedChart].xAxis[0].setExtremes(minDays - 1, maxDays + 1);
    } else {
         window[theSelectedChart].xAxis[0].setExtremes(0, categoriesLength);  
    }
} else { 
    window[theSelectedChart].xAxis[0].setExtremes(0, categoriesLength - 1);
}
window[theSelectedChart].exportChart({
    type: "application/pdf",
    url: 'export-chart/',
    filename: localizedShortformExportFilenames[key],
    sourceWidth:(categoriesLength * 12 > 600) ? categoriesLength * 12 : 800,
},{
    scrollbar : {
        enabled : false,
    },
    chart : {
         marginTop : getMarginTop(selectedThumbnail),
         spacingRight : 30,
    },
    title: {
         y:5,
    },
    subtitle : {
         y : 15
    },
});

最佳答案

您不应该使用“window”作为变量名。它保留用于引用您在其中运行 JavaScript 和其他代码的浏览器窗口。对于您的窗口数组,请使用不同的名称,例如“windw”。

关于javascript - 未捕获的类型错误 : Cannot read property '0' of undefined javascript error and with highcharts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26385051/

相关文章:

javascript - 理解 New 与 JavaScript 作用域函数并传递 $

jquery - 在兼容模式下使用 jQuery 检测 IE 版本

php - 无法将 php 变量写入 javascript

highcharts - 如何调整highcharts中网格线的间距

javascript - Highcharts 工具提示在 IE10 和 IE8 以及具有更多数据的 Mozilla 中不支持

javascript - 元素随着页面变宽而重新定位

javascript 通过其他 javascript 对象的一个​​对象方法

javascript - 网络语音 API "Detecting known words"

javascript - 什么更有效率 : listeners or functions in jquery

javascript - 同步页面上的多个(Highcharts)