2016-12-05 49 views
1

我想獲取每個類別的總數據。 point.stackTotal只給出了活動數據的總數。高圖堆積列每個類別的總數據

從我粘貼的代碼示例中,我想知道每個水果的總消耗量。因此,即使我在右上角的圖例上點擊了喬的名字(這使得堆疊圖表上所有喬的信息處於非活動狀態),我仍然知道約翰,簡和喬的蘋果(以及其他任何水果)的總消耗量。鼠標懸停在每個欄類別顯然,我正在尋找的不是point.stackTotal

$(function() { 
    Highcharts.chart('container', { 
     chart: { 
      type: 'column' 
     }, 
     title: { 
      text: 'Stacked column chart' 
     }, 
     xAxis: { 
      categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas'] 
     }, 
     yAxis: { 
      min: 0, 
      title: { 
       text: 'Total fruit consumption' 
      }, 
      stackLabels: { 
       enabled: true, 
       style: { 
        fontWeight: 'bold', 
        color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray' 
       } 
      } 
     }, 
     legend: { 
      align: 'right', 
      x: -30, 
      verticalAlign: 'top', 
      y: 25, 
      floating: true, 
      backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white', 
      borderColor: '#CCC', 
      borderWidth: 1, 
      shadow: false 
     }, 
     tooltip: { 
      headerFormat: '<b>{point.x}</b><br/>', 
      pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}' 
     }, 
     plotOptions: { 
      column: { 
       stacking: 'normal', 
       dataLabels: { 
        enabled: true, 
        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white' 
       } 
      } 
     }, 
     series: [{ 
      name: 'John', 
      data: [5, 3, 4, 7, 2] 
     }, { 
      name: 'Jane', 
      data: [2, 2, 3, 2, 1] 
     }, { 
      name: 'Joe', 
      data: [3, 4, 4, 2, 5] 
     }] 
    }); 
}); 

回答

0

我認爲你應該能夠使用stackLabels.formatter函數顯示你的類別的所有可見和隱藏列的總值。您可以Highcharts API中獲取有關stackLabels的更多信息: http://api.highcharts.com/highcharts/yAxis.stackLabels.formatter

stackLabels: { 
    enabled: true, 
    style: { 
     fontWeight: 'bold', 
     color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray' 
    }, 
    formatter: function() { 
     var x = this.x, 
     value = 0; 

     series = this.axis.series; 
     Highcharts.each(series, function(s) { 
     value += s.userOptions.data[x]; 
     }); 
     return value; 
    } 
    } 

在這裏你可以看到非常簡單的例子,你如何可以實現類似於所需圖表的內容: http://jsfiddle.net/h8f30uwo/

最佳,