0
votes

So, I have stacked bar chart and I want to hide data labels when they don't fit in the area. for Example in Category 8, not to have data label "4" at all. This is a similar question bolow: Highcharts stacked bar chart hide data labels not to overlap But My problem is I also need to hide lables on exporting

I have done this code after generating graph to hide labales

  $.each(this.chartObject.series,function(i,data_series){
           if (data_series.visible){
              $.each(data_series.data,function(j,data){
                if(data.yBottom != null && data.plotY != null){
                  if(data.yBottom - data.plotY < 15){
                    if (typeof data.dataLabel != 'undefined'){
                       data.dataLabel.hide();
                     }
                  }
               }
             });
            }
         });
1

1 Answers

2
votes

You need to move loop from callback, into chart / events / load.

chart: {
        events: {
            load: function () {
                var chart = this;

                $.each(chart.series, function (i, serie) {
                    $.each(serie.data, function (j, data) {

                            if (data.yBottom - data.plotY < 15) data.dataLabel.hide();
                    });
                });
            }
        },
        renderTo: 'chart',
        defaultSeriesType: 'bar'
    },

Example: http://jsfiddle.net/HA5xE/20