无法在highcharts中的固定列栏中获取百分比

问题描述 投票:-2回答:1

嗨,我是highcharts的新手,并且难以获得适当的固定柱形图来处理百分比值。

我想要:

chart with stacked bars

但我能够实现:

chart with plain bars

highcharts percentage
1个回答
0
投票

您可以使用series.dataLabels.formatter回调格式化数据标签。检查下面发布的演示和代码。

码:

  series: [{
    name: 'NSV',
    color: 'rgba(165,170,217,1)',
    data: [38891, 35098, 21296, 19345, 19092],
    pointPadding: 0.3,
    pointPlacement: -0.2
  }, {
    name: 'Margin',
    color: 'rgba(126,86,134,.9)',
    data: [8594.911, 6422.934, 5302.704, 580.35, 3417.468],
    pointPadding: 0.4,
    pointPlacement: -0.2,
    dataLabels: {
     formatter: function() {
      var chart = this.series.chart,
        percentage = (this.y / chart.series[0].points[this.point.index].y) * 100;

        return percentage.toFixed(1) + '%';
     }
    }
  }]

演示:

API参考:

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