Change window position with button for stock chart - Javascript highcharts

Javascript examples for highcharts:Stock Chart

Description

Change window position with button for stock chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> 
      <script src="https://code.highcharts.com/stock/highstock.js"></script> 
      <script src="https://code.highcharts.com/stock/modules/exporting.js"></script> 
      <script src="https://code.highcharts.com/stock/modules/export-data.js"></script> 
      <div id="container" style="height: 400px; min-width: 310px"></div> 
      <button id="increaseRange">Increase Selected Range</button> 
      <script type="text/javascript">
$.getJSON('https://www.highcharts.com/samples/data/aapl-c.json', function (data) {
    // Create the chart
    var chart = Highcharts.stockChart('container', {
        rangeSelector: {/*from ww  w.j av a2 s.  com*/
            selected: 1
        },
        title: {
            text: 'AAPL Stock Price'
        },
        series: [{
            name: 'AAPL',
            data: data,
            tooltip: {
                valueDecimals: 2
            }
        }]
    });
    var btn = document.getElementById('increaseRange')
    btn.onclick = function() {
          var axis = chart.xAxis[0]
          var ext = axis.getExtremes()
        var range = ext.max - ext.min
        var addRight = function() {
           axis.setExtremes(ext.min, ext.max + range)
        }
        var addLeft = function() {
           axis.setExtremes(ext.min - range, ext.max)
        }
        var alignToRightEdge = function() {
           axis.setExtremes(ext.min, ext.dataMax)
        }
        if (ext.max + range < ext.dataMax) {
           addRight()
        } else if (ext.min - range > ext.dataMin) {
           alignToRightEdge()
           addLeft()
        } else {
           axis.setExtremes(ext.dataMin, ext.datamax)
        }
    }
});

      </script>  
   </body>
</html>

Related Tutorials