score:1

Accepted answer

You can:

a) Set min property for an x-axis in a navigator:

  navigator: {
    xAxis: {
      min: currentTimestamp - 6 * 60 * 60 * 1000, // 6 hours
    }, 
    // adaptToUpdatedData: false,
    ...
  }

Live example: https://stackblitz.com/edit/js-m38td3?file=index.js

API Reference: https://api.highcharts.com/highstock/navigator.xAxis


b) Enable rangeSelector.allButtonsEnabled property and use afterBtnClick Highcharts event. The event afterSetExtremes is not called if the extremes are the same as the current one (they are because of initial min and max restriction).

chart: {
  zoomType: 'x',
  events: {
    load: function() {
      Highcharts.addEvent(
        this.rangeSelector,
        'afterBtnClick',
        function() {
          const button = this.buttonOptions[this.selected];
          const chart = this.chart;

          afterSetExtremes({
            target: {
              chart
            },
            min: chart.xAxis[0].dataMax - button._range,
            max: chart.xAxis[0].dataMax
          });
        });
    }
  }
}

Live demo: https://stackblitz.com/edit/js-tuzuuz?file=chartOptions.js,index.js,index.html

Docs: https://www.highcharts.com/docs/extending-highcharts/extending-highcharts


Related Articles