2016-08-30 55 views
1

如果值为零,我有隐藏标签内数字的代码。我的问题是,我也想隐藏显示在列上的总和号码。如果为零,则隐藏stacklabel

这里是一个例子,最后一个标签。 http://jsfiddle.net/4NxYh/72/

plotOptions: {      
    line: {dataLabels: {enabled: true, style: {fontSize: '8px'}, style: {textShadow: false}, allowDecimals: true, formatter: function() {return this.y + 'e'}}}, 
    column: {stacking: 'normal', shadow: false, dataLabels: { 
         formatter:function() { 
          if(this.y != 0) { 
           return this.y; 
          } 
         }, 
         enabled: true, 
         color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white', 
         style: { 
          textShadow: '0 0 3px black', 
          fontSize: '8px' 
         } 
        }}, 
    series: {minPointLength: 0} 

},

回答

1

为了隐藏堆栈总数时,总数量是零,您可以将您的dataLabels格式化的stackLabels属性类似的变种(见this Stack Overflow question谈到有关格式stackLabels)。

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

在这种情况下,如果您的总数大于零,请显示堆栈标签。如果没有,什么都不显示。

这是你的提琴的更新版本与此变化:http://jsfiddle.net/brightmatrix/4NxYh/76/

我希望这是对你有帮助!

+1

谢谢麦克,非常有帮助! – Andy

相关问题