2013-05-21 68 views
6

我试图让我的用户可以将最大plotLine添加到图表,并让它更改图表的背景颜色,如果情节高于该线条。我似乎无法获得更新剧情的方法。我已经试过:Highcharts动态添加/更改yAxis plotLines

chart.yAxis[0].update({ 
    plotLines: [{ 
     id: 'limit-max', 
     color: 'blue', 
     dashStyle: 'LongDashDot', 
     width: 1, 
     value: 45000, 
     zIndex: 0 
    }] 
}); 

,但我得到的错误:

TypeError: a is undefined

...dBands,function(a){a.render()});n(this.series,function(a){a.isDirty=!0})},setCat...

highcharts.js (line 136)

+1

由于我无法找到我使用的代码,我只会留下评论。尝试删除plotLine,然后重新添加新值。 – wergeld

+0

这样做 - 我只是没有开始,然后使用更新来添加它。 – jbolanos

回答

4

只能破坏和创造新的plotLins,因为update()函数不可用。

+0

我将plotLines从源代码中剥离出来,并允许用户在创建图表后添加它。 – jbolanos

+5

您可以使用addPlotLine函数来执行此操作.http://api.highcharts.com/highcharts#Axis.addPlotLine() –

1

这里是为我工作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(); 
2

只需添加此代码,然后你可以使用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(); 
 
     } 
 
    }

+0

感谢这很好。只需传递你需要更新的属性,它就会工作:'chart.series [0] .xAxis.plotLinesAndBands [0] .update({“color”:“#eeeeee”});' – Mark

0

我试图分配一个ID绘制线,

首先将剧情片完全删除removePlotLine(id),然后再将其添加回addPlotLine。这对我很有效。

function upgradePlotLine(new_line) { 
    chart.yAxis[0].removePlotLine('my_line'); 
    chart.yAxis[0].addPlotLine(new_line); 
}