我正在尝试实现一个Highcharts,以便在.NET MVC中动态地将新系列加载到同一个图表中。我只需要根据一些属性将相同的数据集分组到几个组中,并将这些组显示为多个序列。选择要分组的属性是使用单选按钮完成的。我已经使用Jquery编写了一个'on change‘事件处理程序。为了加载多个系列,我删除了所有当前系列并添加了新系列。但它们返回两个错误。
while (chart.series.length > 0) {
chart.series[0].remove(false);
}
chart.redraw();
这个块破坏了现有的系列。但是它返回下面的错误。
Uncaught TypeError: Cannot read property 'isSVG' of undefined
at a.SVGElement.destroy (highcharts.js:53)
at highcharts.js:212
at Array.forEach (<anonymous>)
at a.each (highcharts.js:28)
at a.Legend.destroyItem (highcharts.js:212)
at k.destroy (highcharts.js:286)
at d (highcharts.js:316)
at a.fireEvent (highcharts.js:31)
at k.remove (highcharts.js:316)
at k.remove (highcharts.js:334)
destroy @ highcharts.js:53
(anonymous) @ highcharts.js:212
a.each @ highcharts.js:28
destroyItem @ highcharts.js:212
destroy @ highcharts.js:286
d @ highcharts.js:316
a.fireEvent @ highcharts.js:31
remove @ highcharts.js:316
remove @ highcharts.js:334
(anonymous) @ StackedChart:285
dispatch @ jquery-1.10.2.js:5109
elemData.handle @ jquery-1.10.2.js:4780
以下是加载新系列的代码。
if (i != (workCenterData.length - 1))
chart.addSeries({ data: dataArray }, false);
else
chart.addSeries({ data: dataArray }, true);
此块返回以下错误。
Uncaught TypeError: Cannot read property 'setAttribute' of undefined
at a.SVGElement.fillSetter (highcharts.js:59)
at a.SVGElement.<anonymous> (highcharts.js:43)
at a.objectEach (highcharts.js:29)
at a.SVGElement.attr (highcharts.js:42)
at a.Legend.colorizeItem (highcharts.js:212)
at a.Legend.renderItem (highcharts.js:217)
at highcharts.js:220
at Array.forEach (<anonymous>)
at a.each (highcharts.js:28)
at a.Legend.render (highcharts.js:220)
fillSetter @ highcharts.js:59
(anonymous) @ highcharts.js:43
a.objectEach @ highcharts.js:29
attr @ highcharts.js:42
colorizeItem @ highcharts.js:212
renderItem @ highcharts.js:217
(anonymous) @ highcharts.js:220
a.each @ highcharts.js:28
render @ highcharts.js:220
redraw @ highcharts.js:232
C @ series-label.js:9
a.(anonymous function) @ highcharts.js:19
(anonymous) @ highcharts.js:307
a.fireEvent @ highcharts.js:31
addSeries @ highcharts.js:306
(anonymous) @ StackedChart:314
dispatch @ jquery-1.10.2.js:5109
elemData.handle @ jquery-1.10.2.js:4780
我尝试了这两种销毁方法,然后在一个普通的HTML页面上单击一个按钮,然后重新生成新的系列,它就能正常工作。也许这和.NET有关,因为我参考了很多论坛,他们推荐了这些方法。抱歉,我不能包含小提琴,因为我的数据是从数据库中获取的。你有什么想法来动态加载或者摆脱这些错误吗?
发布于 2017-10-31 13:25:32
不要紧,我添加了一个假的图例项目作为图例标题,但我还编写了一个函数来销毁这个图例标题的符号。注释掉这个函数确实起到了作用。它按照我现在想要的方式工作。
https://stackoverflow.com/questions/47014037
复制相似问题