ChartJS Line Chart
Multiple Line Chart
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.js"></script>
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
<div id="time">(time)</div>
</body>
CSS
canvas { background-color : #eee;
}
JavaScript
var options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [
{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderWidth: 1
}
]
},
options: {
animation: {
easing: 'linear',
duration: 10000
},
scales: {
yAxes: [{
ticks: {
reverse: false
}
}]
}
}
}
var timeDiv = document.getElementById('time');
function updateTime(start) {
var ms = performance.now() - start;
timeDiv.textContent = '' + Math.round(ms/100)/10;
}
Chart.plugins.register({
id: 'timer',
beforeRender(chart, options) {
this.start = performance.now();
},
afterDraw() {
updateTime(this.start);
},
afterRender(chart, options) {
updateTime(this.start);
}
});
var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);