Highcharts Demo
author(s):
Torstein Hønsi
HTML
<script src="https://code.jquery.com/jquery-3.2.0.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<button id="zoom">
Zoom
</button>
JavaScript
var data = [];
var date = Date.UTC(2017,03,25,09,32,21);
for (var i = 0; i < 100; i++){
date = date + i*1000 * 60 * 60
data.push([date, i])
}
var chart = Highcharts.chart('container', {
chart: {
type: 'spline',
zoomType: 'xy'
},
title: {
text: 'Snow depth at Vikjafjellet, Norway'
},
subtitle: {
text: 'Irregular time data in Highcharts JS'
},
xAxis: {
type: 'datetime',
tickInterval: 1000,
minRange: 1000,
title: {
text: 'Date'
}
},
yAxis: {
title: {
text: 'Snow depth (m)'
},
min: 0
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x:%e. %b}: {point.y:.2f} m'
},
plotOptions: {
spline: {
marker: {
enabled: true
}
}
},
series: [{
name: 'Winter 2012-2013',
// Define the data points. All series have a dummy year
// of 1970/71 in order to be compared on the same x axis. Note
// that in JavaScript, months start at 0 for January, 1 for February etc.
data: data
}]
});
$("#zoom").on("click",function(){
chart.xAxis[0].setExtremes(data[50][0] - 6000, data[50][0] + 6000);
chart.showResetZoom();
});