javascript Highcharts 动态添加/更改 yAxis plotLines
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16676922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Highcharts dynamically add/change yAxis plotLines
提问by jbolanos
I'm trying to make it possible for my users to add a max plotLine to a chart and have it change the background color of the chart if a plot goes above that line. I can't seem to get a method to update the plotlines. I've tried:
我试图让我的用户可以将最大 plotLine 添加到图表,并在绘图超出该线时更改图表的背景颜色。我似乎无法获得更新情节线的方法。我试过了:
chart.yAxis[0].update({
plotLines: [{
id: 'limit-max',
color: 'blue',
dashStyle: 'LongDashDot',
width: 1,
value: 45000,
zIndex: 0
}]
});
but I get the error:
但我收到错误:
TypeError: a is undefined
...dBands,function(a){a.render()});n(this.series,function(a){a.isDirty=!0})},setCat...
highcharts.js (line 136)
类型错误:a 未定义
...dBands,function(a){a.render()});n(this.series,function(a){a.isDirty=!0})},setCat...
highcharts.js(第 136 行)
回答by Sebastian Bochan
You can only destroy and create new plotLins, because update() function is not available.
您只能销毁和创建新的 plotLins,因为 update() 函数不可用。
回答by Akram Kamal Qassas
just add this code and then you can use the plotline.update method
只需添加此代码,然后您就可以使用 plotline.update 方法
//Add support for update method
Highcharts.PlotLineOrBand.prototype.update = function (newOptions){
var plotBand = this;
Highcharts.extend(plotBand.options, newOptions);
if (plotBand.svgElem) {
plotBand.svgElem.destroy();
plotBand.svgElem = undefined;
plotBand.render();
}
}
回答by Thomas Vo
Here's what worked for me http://jsfiddle.net/tx1kt0bj/2/
这是对我有用的 http://jsfiddle.net/tx1kt0bj/2/
var plotBand = tempAxis.plotLinesAndBands[0];
$.extend(plotBand.options, {
color: '#000',
to: 10,
from: 2
});
plotBand.svgElem.destroy();
plotBand.svgElem = undefined;
plotBand.render();
回答by Yifei
I tried to assign an id to plotLine,
我试图为 plotLine 分配一个 id,
First remove the plotline completely by removePlotLine(id)
, then added it back by addPlotLine
. It works great for me.
首先由 完全删除情节线removePlotLine(id)
,然后由将其添加回来addPlotLine
。这对我很有效。
function upgradePlotLine(new_line) {
chart.yAxis[0].removePlotLine('my_line');
chart.yAxis[0].addPlotLine(new_line);
}