I have a stock chart of the Highcharts library. How to adjust the position of the right and left slider in the picture. I need that when I click on the “now” button, the left slider moves to today’s date, and the right one is at a distance from it, for example, 3 hours enter image description here
As I understood in this library, the position of the left slider is dancing from the position of the right one. I implemented moving the left slider for the number of seconds I needed. But it’s dancing from the same right-hand runner…
Alexandra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
You are looking for the setExtremes
method. You can use it in the click
event as below:
rangeSelector: {
buttons: [..., {
text: 'now',
title: 'View current date',
events: {
click: function(e) {
const now = new Date().getTime();
chart.xAxis[0].setExtremes(now, now + HOUR * 3);
return false;
}
}
}]
}
Live demo: https://jsfiddle.net/BlackLabel/5gvdy8oa/
API Reference:
https://api.highcharts.com/highstock/rangeSelector.buttons.events.click
https://api.highcharts.com/class-reference/Highcharts.Axis#setExtremes