set xAxis range when using xAxis Categories for line chart - Javascript highcharts

Javascript examples for highcharts:Chart Axis

Description

set xAxis range when using xAxis Categories for line chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.7.1.js"></script> 
      <script type="text/javascript">
    $(function(){//ww w .j a  va  2 s. co m
var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container'
    },
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar'],
        minRange: 1
    },
    series: [{
        data: [29.9, 71.5, 106.4]
    }]
});
$('#show-all-months').click(function() {
    //chart.xAxis[0].setCategories(['Jan', 'Feb','Mar']);
    chart.xAxis[0].setExtremes(0,2);
});
$('#show-two-months').click(function() {
    //chart.xAxis[0].setCategories(['Jan', 'Feb']);
    chart.xAxis[0].setExtremes(0,1);
});
    });

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://code.highcharts.com/modules/exporting.js"></script> 
      <button id="show-all-months">All Months</button> 
      <button id="show-two-months">2 Months</button> 
      <div id="container" style="height: 300px"></div>  
   </body>
</html>

Related Tutorials