skip to Main Content

I use Highcharts to plot the graph, but there is a problem I am facing. data contains the values from 1 to n. So I want the yAxis column to start at 1. I set yAxis min = 1 but it doesn’t fix my problem.

Here is a jsfiddle that illustrates the problem I am having:
Link

yAxis: {
  title: null,
  endOnTick: false,
  min: 1
}

Is there any way to solve my problem? I expect it like this:

I expect it like this

2

Answers


  1. Chosen as BEST ANSWER

    Thanks for ppotaczek answer. I find it pretty cool, can ignore blanks, starting from the smallest element. I have a solution for this and am posting it here for anyone who needs it.

      tickPositioner: function () {
            var positions = [],
                tick = Math.floor(this.dataMin),
                increment = Math.ceil((this.dataMax - this.dataMin) / 6);
    
            if (this.dataMax !== null && this.dataMin !== null) {
                for (tick; tick - increment <= this.dataMax; tick += increment) {
                    positions.push(tick);
                }
            }
            return positions;
        }
    

  2. The simplest solution is to use tickPositioner function and modify the first tick. For example:

      yAxis: {
        title: null,
        tickPositioner: function() {
          const tickPositions = [...this.tickPositions];
          tickPositions[0] = 1;
          return tickPositions;
        },
        endOnTick: false,
        startOnTick: false,
        min: 1
      }
    

    Live demo: https://jsfiddle.net/BlackLabel/rf3cm8Lw/

    API Reference: https://api.highcharts.com/highcharts/xAxis.tickPositioner

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search