Skip to content

Instantly share code, notes, and snippets.

@ricklon
Created July 18, 2017 01:08
Show Gist options
  • Save ricklon/308160366c47a0686cde56e2c7a2b04e to your computer and use it in GitHub Desktop.
Save ricklon/308160366c47a0686cde56e2c7a2b04e to your computer and use it in GitHub Desktop.
app.controller("lineCtrl", function($scope, socket) {
var timeFormat = 'MM/DD/YYYY HH:mm:ss';
var color = Chart.helpers.color;
function newDateString(seconds) {
return moment().add(seconds, 's').format();
}
function newTimestamp(days) {
return moment().add(days, 'd').unix();
}
$scope.labels = [newDateString(1), newDateString(2), newDateString(3), newDateString(4), newDateString(5)];
$scope.series = ['Temp', 'High', 'Low'];
$scope.data = [
[21, 22, 23, 24, 2],
[33, 33, 33, 33, 33],
[10, 10, 10, 10, 10]
];
$scope.onClick = function(points, evt) {
console.log(points, evt);
};
socket.on('sendTemp', function(data) {
$scope.data.push([data.curTemp], [20], [35]);
$scope.labels.push(moment().format());
});
$scope.onClick = function(points, evt) {
console.log(points, evt);
};
$scope.options = {
responsive: true,
title: {
display: true,
text: "Chart.js Time Point Data"
},
scales: {
xAxes: [{
type: "time",
display: true,
scaleLabel: {
display: true,
labelString: 'Date'
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'value'
}
}]
},
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment