我正在使用 highchart 来实现一些向下钻取功能。
我有一个功能可以让用户单击面积图并添加一条线。但后来我发现我的函数有一个错误。这些图表之间应该只有一条红线,但是当用户单击另一个图表时,第一个图表上的现有红线不会被删除。
以下是我分享的图表功能。
var myPlotLineId = "myPlotLine";
addPlotLine = function(evt) {
var point = evt.point;
var xValue = point.x;
var xAxis = point.series.xAxis;
Highcharts.each(xAxis.plotLinesAndBands, function(p) {
if (p.id === myPlotLineId) {
p.destroy();
}
});
xAxis.addPlotLine({
value: xValue,
width: 1,
color: 'red',
id: myPlotLineId
});
};
因为我使用的是 ID,所以它应该只允许一条红线。
The below is the current situation.
由于我使用 id 作为情节线,因此不允许有两行,请参阅我的示例:
http://jsfiddle.net/Xm4vW/74/ http://jsfiddle.net/Xm4vW/74/
我只想要许多图表中的一条红线
更新1:
我在新的演示中尝试了 redraw() :http://jsfiddle.net/Xm4vW/80/ http://jsfiddle.net/Xm4vW/80/
但这没有帮助。
如果问题不够清楚,请告诉我。
没有什么比“Highcharts.each(xAxis.plotLinesAndBands, function(p)”更好的了。通过循环迭代图表并使用“removePlotLine(PlotLineID)”而不是“destroy()”:
for(i=0;i<Highcharts.charts.length; i++){
var chart=Highcharts.charts[i];
chart.xAxis[0].removePlotLine('myPlotLineId');
}
并在括号中设置 id:
id: 'myPlotLineId'
这是jsfiddlehttp://jsfiddle.net/asadsarwar89/bh4kz9rw/ http://jsfiddle.net/asadsarwar89/bh4kz9rw/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)