Reputation: 4183
I have a highstock chart that displays sensor data using ajax request. Everytime the extremes change on the xAxis I am loading the relevant data from the server and display it. On the page I also have two dateTime controls to select start and end date of the period you want to watch the data from.
Now I have the problem that when I set start to 11/28/2012 and end also to 11/28/2012 and I scroll (minimum range is 1 day) the user is able to scroll out of the selected range which I am trying to prohibit.
I couldn't find any examples or solutions that work.
I tried setting the chart.navigator.xAxis.min and max, also tried to set chart.xAxis.min and max but this isn't working...
Take a look yourself here: http://carbocount.wikidot.com/project:products:visualization
Upvotes: 0
Views: 1544
Reputation: 4183
I managed to fix this problem on my own.
In the afterSetExtremes
event I checked the extremes using e.dataMin
and e.dataMax
if the range is between the selected time period. It not I reset the extremes:
// if the user tries to zoom outside of the selected time period
// cancel the event and reset extremes
var extremesReset = false;
if (e.dataMin < plotStart.getTime()) {
e.dataMin = plotStart.getTime();
extremesReset = true;
}
if (e.dataMax > plotEnd.getTime()) {
e.dataMax = plotEnd.getTime();
extremesReset = true;
}
var chart = $('#plot').highcharts();
if (extremesReset)
chart.xAxis[0].setExtremes(e.dataMin, e.dataMax);
Upvotes: 1