2017-03-07 104 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