Pri_stack
Pri_stack

Reputation: 189

is there any way we can append last value forcefully on x-axis?

I have min and max value for x-axis. If my minvalue=0 and maxvalue=23 i want my x-axis scale to range from 0-23 but due to the automatic tickinterval adjustment(eg. 2) my x-axis scale ranges from 0-24. how do i restrict it to 23 ?

Upvotes: 0

Views: 20

Answers (1)

ppotaczek
ppotaczek

Reputation: 39079

You can use tickPositions or tickPositioner option, for example:

const breaks = 10;
const dataMin = 0;
const dataMax = 23;
const step = Math.round((dataMax - dataMin) / breaks * 100) / 100;

Highcharts.chart('container', {
  ...,
  xAxis: {
    tickPositioner: function() {
      const positions = [];

      for (var i = dataMin; i < (dataMax - step / 2); i += step) {
        positions.push(Math.round(i * 100) / 100);
      }

      positions.push(dataMax);

      return positions;
    }
  }
});

Live demo: http://jsfiddle.net/BlackLabel/6m4e8x0y/4927/

API Reference:

https://api.highcharts.com/highcharts/xAxis.tickPositions

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

Upvotes: 1

Related Questions