【问题标题】:Datalabels only showing the latest value plotted on the max value数据标签仅显示绘制在最大值上的最新值
【发布时间】:2019-08-19 00:42:28
【问题描述】:

我在 yAxis.max 上绘制了一些值,唯一的问题是数据标签仅显示最新值。

这是小提琴https://jsfiddle.net/stefadan83/uqyovdhr/2/ 我希望值 950, 189, 145 可见,而不是只有 145。

我希望绘制在最大值上的所有值都有标签。

【问题讨论】:

    标签: typescript vue.js highcharts


    【解决方案1】:

    dataLabels.formatter 回调中更新点是个坏主意。相反,更新chart.load 事件回调中的点并将实际值保存为例如。 point.realValue。然后在dataLabels.formatter 中使用它来显示最大值:

    chart: {
      renderTo: 'container',
      type: 'line',
      events: {
        load: function() {
          var chart = this;
    
          chart.series.forEach(function(series) {
            series.points.forEach(function(point) {
              if (point.y > 100) {
                point.realValue = point.y;
    
                point.update({
                  y: 100
                }, false, false);
              }
            });
          });
    
          chart.redraw(false);
        }
      }
    }
    
    ...
    
    plotOptions: {
      line: {
        dataLabels: {
          enabled: true,
          formatter: function() {
            if (this.point.realValue > 100) {
              console.log(this);
    
              return this.point.realValue;
            }
          }
        }
      }
    }
    

    演示:

    API 参考:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-16
      • 2013-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多