垂直数据标签在Bar Highchart中被切除

问题描述 投票:0回答:1

我尝试了以下演示[在此处输入链接描述] [1]

[1]:https://jsfiddle.net/6snza1fo/ enter code here

highcharts
1个回答
0
投票

您可以以轴为单位计算所需空间,并使用setExtremes方法应用它:

chart: {
  height: 205,
  width: 200,
  background: '#F2F2F2',
  events: {
    load: function() {
      var maxPxY = 0,
        yAxis = this.yAxis[0];

      this.series.forEach(function(s) {
        s.points.forEach(function(p) {
          if (p.dataLabel && p.dataLabel.alignAttr.y < maxPxY) {
            maxPxY = p.dataLabel.alignAttr.y;
          }
        });
      });

      if (maxPxY) {
        yAxis.setExtremes(null, yAxis.toValue(maxPxY));
      }
    }
  }
}

实时演示: https://jsfiddle.net/BlackLabel/amwefro6/1/

API参考:

https://api.highcharts.com/class-reference/Highcharts.Axis#toValue

https://api.highcharts.com/highcharts/chart.events.load

© www.soinside.com 2019 - 2024. All rights reserved.