【问题标题】:HighCharts display total of stacked column in labelsHighCharts 显示标签中堆叠列的总数
【发布时间】:2017-07-28 06:04:36
【问题描述】:

我有一个堆叠组柱形图,如下面提供的小提琴所示。在 xAxis 标签(红色块)中,我想显示从第二列的总数中减去的堆积量的总数。例如,对于“Value1”,我想在标签 (100-(43+15)) 中显示 42。现在,我只能访问 x 值,这些值在格式化程序函数 (this.value) 中返回。 https://jsfiddle.net/er1187/n6sr0znx/

xAxis: [{
    offset: -280,
    tickWidth: 0,
    lineWidth: 0,
    categories: ['Value1', 'Value2', 'Value3'],
    labels: {
        x: 5,
        useHTML: true,
        style:{
        backgroundColor: 'red',
        color: 'white'
        },
        formatter: function () {
            return this.value;
        }
    }
}, {
    linkedTo: 0,
    categories: ['Value1', 'Value2', 'Value3']
}]

【问题讨论】:

    标签: highcharts axis-labels


    【解决方案1】:

    在轴格式化程序中,您还无法访问已处理的数据。但是,您可以访问系列的选项并获取原始数据。

    formatter: function () {
      const axis = this.axis;
      const points = axis.series.map(series =>
        series.options.data[axis.categories.indexOf(this.value)]
      );
    
      return points[2] - (points[0] + points[1]);    
    }
    

    示例:https://jsfiddle.net/n6sr0znx/2/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-13
      • 2018-09-01
      • 1970-01-01
      相关资源
      最近更新 更多