1

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:

enter image description here

What I am getting:

enter image description here

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 enter image description here

Reddy
  • 1,477
  • 29
  • 79

1 Answers1

2

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/

Kacper Madej
  • 7,846
  • 22
  • 36
  • **@Kacper Madej**... Thanks for the answer. But it did not solved my problem :( My all values are `[59, 56, 50, 52, 61, 80, 79, 100]` and `[39, 35, 19, 38, 39, 48, 56, 57]` which are **below 100**, but I am getting max value as **157** in yAxis... I want to identify max value of the charts and set that as maxLabel – Reddy Apr 17 '16 at 23:49
  • 1
    @Reddy Sine there is stacking set, then max value is 100 + 57, so 157. Disable stacking to get max of 100 - http://jsfiddle.net/e6har510/1/ – Kacper Madej Apr 18 '16 at 10:39
  • **@Kacper Madej**, This is what exactly I am looking for... Thanks for the TIP – Reddy Apr 18 '16 at 14:16