2013-08-16 49 views
1

我想爲高點添加點而不期望滿足所有類別。 有可能嗎?任何工作? 當X數據是基於時間的時候,我做了同樣的事情,但是可以用其他類型的數據來完成嗎?例如,一個系列可能只是蘋果和橘子,而不是其他類別。見代碼:高分添加點但不適用於所有類別

$(function() { 
    $('#container').highcharts({ 
     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: -70, 
      verticalAlign: 'top', 
      y: 20, 
      floating: true, 
      backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white', 
      borderColor: '#CCC', 
      borderWidth: 1, 
      shadow: false 
     }, 
     tooltip: { 
      formatter: function() { 
       return '<b>'+ this.x +'</b><br/>'+ 
        this.series.name +': '+ this.y +'<br/>'+ 
        'Total: '+ this.point.stackTotal; 
      } 
     }, 
     plotOptions: { 
      column: { 
       stacking: 'normal', 
       dataLabels: { 
        enabled: true, 
        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white' 
       } 
      } 
     }, 
     series: [{ 
      name: 'John', 
      data: [[Apples,5], [Oranges, 6]] 
     }, { 
      name: 'Jane', 
      data: [[Grapes,2]] 
     }, { 
      name: 'Joe', 
      data: [[Grapes,2], [Bananas, 4]] 
     }] 
    }); 
}); 

回答

3

您可以使用索引到你的類別:http://jsfiddle.net/BwyAj/

var categories = ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas'] 

...

series: [{ 
     name: 'John', 
     data: [[categories.indexOf('Apples'),5], [categories.indexOf('Oranges'), 6]] 
    }, { 
     name: 'Jane', 
     data: [[categories.indexOf('Grapes'),2]] 
    }, { 
     name: 'Joe', 
     data: [[categories.indexOf('Grapes'),2], [categories.indexOf('Bananas'), 4]] 
    }] 
相關問題