在一页中,我们正在加载 amcharts4 地图、折线图和饼图以及大量数据。
当页面地图图表的 onload 未正确加载并且在浏览器控制台中它会引发一堆控制台错误。
这里的错误
zone.js:199 Uncaught TypeError: Cannot read property 'push' of null
at ExportMenu.push../node_modules/@amcharts/amcharts4/.internal/core/export/ExportMenu.js.ExportMenu.draw (ExportMenu.js:209)
at ExportMenu.push../node_modules/@amcharts/amcharts4/.internal/core/export/ExportMenu.js.ExportMenu.validate (ExportMenu.js:171)
at Object.dispatch (EventDispatcher.js:381)
at EventDispatcher.js:266
at Module.each (Array.js:74)
at EventDispatcher.push../node_modules/@amcharts/amcharts4/.internal/core/utils/EventDispatcher.js.EventDispatcher._eachListener (EventDispatcher.js:239)
at EventDispatcher.push../node_modules/@amcharts/amcharts4/.internal/core/utils/EventDispatcher.js.EventDispatcher.dispatchImmediately (EventDispatcher.js:264)
at Registry.push../node_modules/@amcharts/amcharts4/.internal/core/Registry.js.Registry.dispatchImmediately (Registry.js:209)
at System.push../node_modules/@amcharts/amcharts4/.internal/core/System.js.System.update (System.js:299)
at System.js:343
当我们尝试在图表组件中注释以下行时,它不会引发错误,而是会丢失导出功能
if (chartConfig.export && chartConfig.export.enabled) {
newChart.exporting.menu = new am4core.ExportMenu();
newChart.exporting.menu.verticalAlign = chartConfig.export.valign as am4core.VerticalCenter;
newChart.exporting.menu.align = chartConfig.export.halign as am4core.Align;
}
那么是什么导致了这些错误,我该如何修复这些错误并保持导出功能?