2013-02-22 34 views
1

我“米工作类似于以下http://jsfiddle.net/7FdQR/1/ignoreHiddenSeries没有在X轴隐藏值,如果显示的系列有空数据

$(function() { 
var chart; 
$(document).ready(function() { 
    chart = new Highcharts.Chart({ 
     chart: { 
      renderTo: 'container', 
      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: -100, 
      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: [null, 3, 7, 2, null] 
     }, { 
      name: 'Jane', 
      data: [2, 2, 3, 2, 1] 
     }, { 
      name: 'Joe', 
      data: [3, 4, 4, 2, 5] 
     }] 
    }); 
}); 

})一highchart;

如果你看一下数据对于John,你会看到一些苹果和香蕉的空值。

如果我们禁用Jane和Joe系列,只留下John的信息,我们仍然可以看到x轴上的所有水果类别,即使有空值约翰的数据集和ignoreHiddenSeri es设置为true。我想在这里实现的是将x轴重新绘制为仅显示橘子,梨和葡萄标签(而不是在x轴上的苹果和香蕉标签)。有没有办法在highchart中做到这一点?

谢谢!

回答

0

找到了解决方案。它可能不是最好的,但它的工作原理http://jsfiddle.net/Hm8T9/

我创建了一个小脚本,并使用setExtremes()函数为xAxis手动设置mins和max。

此外,如果你曾经处理过< 5个类别,并且不想显示所有这些类别(例如我的示例),请将minRange设置为xAxis为1或任何需要的数字。

xAxis: 
{ 
    minRange: 1 
}