Abiel
Abiel

Reputation: 5455

Rescale Y-axis in Highcharts after zoom while maintaining zoomType=x behavior

I have a time series chart in Highcharts where I would like users to be able to zoom in on specific date ranges. This is possible by setting zoomType: 'x'. However, once the chart is zoomed, the Y-axis does not rescale to best fit the visible data. For instance, if the original Y-axis runs from 0 to 100, and I zoom on an area with data that only runs 91 to 99, then I probably want the Y-axis to change to be 90 to 100 or something similar. Basically, I want figure out how to get Highcharts to re-run its axis-scaling logic considering only the visible data.

A halfway measure is to set zoomType: 'xy' which allows the user to draw a rectangle and zoom on that rectangle. However, this is inconvenient for the user in this context, as all they really want to be able to do is isolate a date range and then study the variation in the data in that range.

Upvotes: 2

Views: 4206

Answers (1)

Quentin
Quentin

Reputation: 1942

If you want to stick to highchart.js and not using highstock.js (as contrary to what they were suggesting here: http://highslide.com/forum/viewtopic.php?f=9&t=13983), you can do the following with your y axis:

yAxis: {                               
   title: {                           
       text: 'Number of appartements' 
   },                                 
   min: null, // Will for min and max to adjust when you zoom                      
   max: null, //                         
   startOnTick: false,                
   minTickInterval: 1,                
   showFirstLabel: false              
},                                     

It works just fine for me,

Quentin

Upvotes: 1

Related Questions