Change dateTimeLabelFormats dynamically based on time selection in stock chart - Javascript highcharts

Javascript examples for highcharts:Chart Label

Description

Change dateTimeLabelFormats dynamically based on time selection in stock chart

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"> 
   </head> 
   <body> 
      <div id="container" style="height: 400px; min-width: 600px"></div> 
      <script src="https://code.highcharts.com/stock/highstock.js"></script> 
      <script src="https://code.highcharts.com/stock/modules/exporting.js"></script> 
      <script type="text/javascript" src="https://www.highcharts.com/samples/data/usdeur.js"></script> 
      <script type="text/javascript">
var chart = Highcharts.stockChart('container', {
  xAxis: {/*from w  w w  . j  a va 2  s. com*/
    type: 'datetime',
    dateTimeLabelFormats: {
      second: '%Y-%m-%d<br/>%H:%M:%S',
      minute: '%Y-%m-%d<br/>%H:%M',
      hour: '%Y-%m-%d<br/>%H:%M',
      day: '%Y<br/>%m-%d',
      week: '%Y<br/>%m-%d',
      month: '%Y-%m',
      year: '%Y'
    }
  },
  rangeSelector: {
    selected: 1,
    buttons: [{
      type: 'month',
      count: 1,
      text: '1m',
      events: {
        click: function() {
          chart.xAxis[0].update({
            labels: {
              format: '{value:%Y-%m}'
            }
          });
        }
      }
    }, {
      type: 'month',
      count: 3,
      text: '3m'
    }, {
      type: 'month',
      count: 6,
      text: '6m'
    }, {
      type: 'ytd',
      text: 'YTD'
    }, {
      type: 'year',
      count: 1,
      text: '1y'
    }, {
      type: 'all',
      text: 'All'
    }]
  },
  series: [{
    name: 'USD to EUR',
    data: usdeur
  }]
});

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

Related Tutorials