Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide zero values in Column chart

Tags:

highcharts

I am using column chart and displaying those value on top of each bar. I don't want to show the values if they are 0. How to do that? Here is my piece of code

var series = {  data: [],   
                dataLabels: {
                    enabled: true,
                    color: 'black',
                    align: 'right',
                    x: -3,
                    y: 3,
                    style: {
                        color: '#333',
                        fontWeight: 'bold',
                        fontSize: '12px',
                        fontFamily: 'Trebuchet MS, Verdana, sans-serif'
                    }
                },
                pointWidth: 28
};
like image 997
arun Avatar asked Apr 05 '13 13:04

arun


3 Answers

You can use the formatter. Something like this should do it:

dataLabels: {
  formatter:function() {
    if(this.y != 0) {
      return this.y;
    }
  }
}

http://api.highcharts.com/highcharts#plotOptions.series.dataLabels.formatter

like image 178
jlbriggs Avatar answered Nov 16 '22 19:11

jlbriggs


You can use datalabels formatter and add condition which check if value is bigger than zero.

http://jsfiddle.net/DdvGm/

plotOptions: {
        series: {
            dataLabels:{
                enabled:true,
                formatter:function(){
                    if(this.y > 0)
                        return this.y;
                }
            }
        }
    },

http://api.highcharts.com/highcharts#plotOptions.column.dataLabels.formatter

like image 30
Sebastian Bochan Avatar answered Nov 16 '22 20:11

Sebastian Bochan


Here is the answer, by how short your question is i am not full sue if the existing answers are correct.

In highcharts 0 is considered a number so it will render it on charts. But null is hidden. So when you are adding data, you have to check if the value is 0 and if it is, then change it to null.

Let me know if you have questions.

Fiddle: http://jsfiddle.net/8kr0tods/ See that may is a 0 and mar is null, and null is hidden.

    if($VAL==0)
    {
        $VAL='null';
    }
like image 38
M H Avatar answered Nov 16 '22 18:11

M H