Custom YTD Option in HighStock Range Selector - Javascript highcharts

Javascript examples for highcharts:Stock Chart

Description

Custom YTD Option in HighStock Range Selector

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Stock Demo</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
      <link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet"> 
      <script type="text/javascript">
$(function() {/*  w w  w  .j  a  v a2  s. com*/
   var startDate  = new Date("April 01, 2012 00:00:00");
    var today = new Date();
    var count =  parseInt((today.getTime() - startDate)/(24*3600*1000)) -1;
    $.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function(data) {
        // Create the chart
        window.chart = new Highcharts.StockChart({
            chart : {
                renderTo : 'container'
            },
            rangeSelector : {
                selected: 1,
                buttonTheme: {
                    width:100
                },
                buttons: [{
                        type: 'ytd',
                        count: 1,
                        text: 'Calendar YTD'
                    },
                       {
                        type: 'day',
                        count: count,
                        text: 'Financial YTD'
                    }]
            },
            title : {
                text : 'AAPL Stock Price'
            },
            series : [{
                name : 'AAPL',
                data : data,
                tooltip: {
                    valueDecimals: 2
                }
            }]
        } );
    });
});

      </script> 
   </head> 
   <body> 
      <div id="container" style="height: 400px; min-width: 600px"></div> 
      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> 
      <script src="https://code.highcharts.com/stock/highstock.js"></script> 
      <script src="https://code.highcharts.com/stock/modules/exporting.js"></script>  
   </body>
</html>

Related Tutorials