2012-08-30 99 views
6

我製作了一張帶分組和堆積列的Highcharts圖表,如下面的示例所示:http://www.highcharts.com/demo/column-stacked-and-grouped。這個例子顯示了5個不同人的許多成果,按性別分組。在這個例子中,我想念的是一個x軸標籤,顯示每個組下面的組(男性或女性)的名稱。是否有可能將此添加到圖表?highcharts列標籤

下面是我試圖製作的圖表的簡化版本:http://jsfiddle.net/WQjVP/66/。它顯示了案件處理系統中三個地點的開放(藍色)和逾期(紅色)問題的數量。每組中的左列顯示7月份該位置的編號,每組中的右列顯示同一單位的8月份編號。我想要做的是在每一列下顯示月份,以便第一列將有「七月」,第二列將有「八月」,第三列將有「七月」等,列和位置標籤。

chart = new Highcharts.Chart({ 
    chart: { 
     renderTo: 'container', 
     type: 'column' 
    }, 
    title: { 
     text: '' 
    }, 
    subtitle: { 
     text: '' 
    }, 
    xAxis: { 
     categories: ["Location A","Location B","Location C"], 
     title: { 
      text: "Location" 
     } 
    }, 
    yAxis: { 
     allowDecimals: false 

    }, 
    plotOptions: { 
     series: { 
      dataLabels: { 
       enabled: true, 
       formatter: function() { 
        if (this.y === 0) { 
         return null; 
        } 
        return this.y; 
       }, 
       style: { 
        color: 'white' 
       } 
      } 
     }, 
     column: { 
      stacking: 'normal', 
      borderWidth: 0 
     } 
    }, 
    series: [{ 
     "color": "rgb(0,0,255)", 
     "name": "open", 
     "data": [18, 2, 6], 
     "stack": "Jul"}, 
    { 
     "color": "rgb(255,0,0)", 
     "name": "overdue", 
     "data": [0, 0, 0], 
     "stack": "Jul"}, 
    { 
     "color": "rgb(0, 0, 255)", 
     "name": "open", 
     "data": [20, 1, 10], 
     "stack": "Aug"}, 
    { 
     "color": "rgb(255, 0, 0)", 
     "name": "overdue", 
     "data": [2, 1, 2], 
     "stack": "Aug"}] 
}); 
+0

也不會把下來作爲一個答案,因爲它是醜陋的。但是,如何創建包含所需標籤的第二個xAxis?將xAxis位置設置爲您需要的位置並移除xAxis線。 – wergeld

回答

15

嘗試使用stackedLabels

yAxis: { 
    stackLabels: { 
     enabled: true, 
     style: { 
      fontWeight: 'bold', 
      color: 'gray' 
     }, 
     formatter: function() { 
      return this.stack; 
     } 
    } 
} 

Demo

reference