Skip to content

Instantly share code, notes, and snippets.

@danemacaulay
Last active September 22, 2015 21:16
Show Gist options
  • Save danemacaulay/fe2481810d3bb2c42ba3 to your computer and use it in GitHub Desktop.
Save danemacaulay/fe2481810d3bb2c42ba3 to your computer and use it in GitHub Desktop.
var now = new Date();
var fullDaysSinceEpoch = Math.floor(now / 8.64e7)
function initChart() {
return new CanvasJS.Chart('chartContainer', {
title: {
text: 'Inform Times'
},
axisX:{
valueFormatString: 'HH:mm'
},
data: [
{
type: 'line',
xValueType: 'dateTime',
dataPoints: []
}
]
});
}
function initializeClickHandlers(chart) {
$('#prev').on('click', function() {
fullDaysSinceEpoch = fullDaysSinceEpoch - 1
renderChart(chart);
});
$('#next').on('click', function() {
fullDaysSinceEpoch = fullDaysSinceEpoch + 1
renderChart(chart);
});
}
function renderChart(chart){
$.ajax({
url: 'http://m9.auslab.2wire.com:8080/data/' + fullDaysSinceEpoch,
cache: false,
success: function(html){
chart.options.data[0].dataPoints = html;
chart.render();
}
});
}
function loadChart() {
var chart = initChart();
renderChart(chart);
initializeClickHandlers(chart);
}
window.onload = loadChart;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment