2017-03-07 103 views
0

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

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'] 
}] 

回答

0

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

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/

+0

这工作,非常感谢! – ellier7