【问题标题】:Highcharts dynamically add/change yAxis plotLinesHighcharts 动态添加/更改 yAxis plotLines
【发布时间】:2017-08-14 13:37:38
【问题描述】:

我正在尝试让我的用户可以将最大 plotLine 添加到图表中,并让它在绘图超出该线时更改图表的背景颜色。我似乎无法获得更新情节线的方法。我试过了:

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

但我得到了错误:

类型错误:a 未定义

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

highcharts.js(第 136 行)

【问题讨论】:

  • 由于我找不到我使用的代码,所以我会留下评论。尝试删除 plotLine 然后用新值重新添加它。
  • 成功了——我只是没有从一个开始,然后使用更新来添加它。

标签: javascript highcharts


【解决方案1】:

您只能销毁并创建新的 plotLins,因为 update() 函数不可用。

【讨论】:

  • 我从源代码中删除了 plotLines,并允许用户在创建图表后添加它。
  • 您可以使用 addPlotLine 函数来做到这一点。api.highcharts.com/highcharts#Axis.addPlotLine()
  • @SebastianBochan - 这个功能被删除了吗?在文档或 Google 中找不到它...
【解决方案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();
        }
    }

【讨论】:

  • 谢谢这很好用。只需传入您需要更新的属性即可:chart.series[0].xAxis.plotLinesAndBands[0].update({ "color": "#eeeeee" });
【解决方案3】:

这对我有用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();

【讨论】:

    【解决方案4】:

    我尝试为 plotLine 分配一个 id,

    首先由removePlotLine(id) 完全删除情节线,然后由addPlotLine 将其添加回来。它对我很有用。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-14
      • 2015-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多