k.p
k.p

Reputation: 67

How to remove the data-range sign if the data is zero on y axis of highcharts?

How to remove the G sign below for zero

enter image description here

Upvotes: 0

Views: 39

Answers (1)

jlbriggs
jlbriggs

Reputation: 17791

You need to use the label formatter() function. This will required that you create the logic to use the abbreviation yourself as well, however.

Example:

yAxis: { 
    labels: {
    formatter: function() {
        return this.value == 0 ? 0 : this.value / 1000000000 + 'G';
    }
  }
}

Fiddle:

Something more flexible could look like this:

yAxis: { 
    labels: {
    formatter: function() {
        var val;
      if(this.value > 1000000000 ) {
        val = this.value / 1000000000  + 'B';
      }
      else if(this.value > 1000000) {
        val = this.value / 1000000 + 'M';
      }
      else if(this.value > 1000) {
        val = this.value / 1000 + 'k';
      }
      else {
        val = this.value;
      }
        return this.value == 0 ? 0 : val;
    }
  }
}

updated fiddle:

Upvotes: 1

Related Questions