Highcharts - yAxis tickInterval to max data

2019-03-01 12:37发布

问题:

I am trying to set max value dynamically of the largest number. I am not sure, where I am doing wrong...

Any help please?

Online Demo

Expected:

What I am getting:

PS: I want to find max value (Eg: 100 in this example) and show that as first yAxisLabel and next values should be minus (-) 20 etc...

Chart 1 values [39, 35, 19, 38, 39, 48, 56, 57]

Chart 2 values [39, 35, 19, 38, 39, 48, 56, 57]

Tried options without luck:

yAxis: {
  min: 0, 
  max: 100,
  tickInterval: 20,
},

and

yAxis: {
  tickInterval: 20,
  tickPositioner: function(min,max){
      var act = min,
          ticks = [];
      console.log(this);
      while(act <= max){
        ticks.push(act);
        act+= this.tickInterval;
      }
      return ticks;  
  },
  min: 0,
  max: 100,
},

Thanks to @Kacper Madej who has given below code which resulted

回答1:

It is possible to use tockPositioner and set ticks there like:

    showLastLabel: false,
    tickPositioner: function(min, max) {
      var ticks = [],
        tick = min,
        step = Math.round((max - min) / 7);

      while (tick < max - step / 2) {
        ticks.push(Math.round(tick));
        tick += step;
      }
      ticks.push(Math.round(max));
      ticks.push(Math.round(max+step)); //hidden - added for top padding

      return ticks;
    }

Example: http://jsfiddle.net/e6har510/



标签: highcharts