2013-03-18 00:57:50 +01:00
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
|
2015-05-16 04:54:01 +02:00
|
|
|
<head>
|
|
|
|
<title>Line Chart</title>
|
|
|
|
<script src="../Chart.js"></script>
|
2015-05-20 09:03:45 +02:00
|
|
|
<script src="../node_modules/jquery/dist/jquery.min.js"></script>
|
2015-05-16 04:54:01 +02:00
|
|
|
</head>
|
2013-03-18 00:57:50 +01:00
|
|
|
|
2015-05-16 04:54:01 +02:00
|
|
|
<body>
|
|
|
|
<div style="width:100%">
|
|
|
|
<div>
|
|
|
|
<canvas id="canvas" height="450" width="600"></canvas>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<button id="randomizeData">Randomize Data</button>
|
|
|
|
<script>
|
|
|
|
var randomScalingFactor = function() {
|
2015-05-20 09:03:45 +02:00
|
|
|
return Math.round(Math.random() * 100 * (Math.random() > 0.5 ? -1 : 1));
|
2015-05-16 04:54:01 +02:00
|
|
|
};
|
|
|
|
var randomColor = function(opacity) {
|
|
|
|
return 'rgba(' + Math.round(Math.random() * 255) + ',' + Math.round(Math.random() * 255) + ',' + Math.round(Math.random() * 255) + ',' + (opacity || '.3') + ')';
|
|
|
|
};
|
2015-01-08 18:13:14 +01:00
|
|
|
|
2015-05-16 04:54:01 +02:00
|
|
|
var lineChartData = {
|
|
|
|
labels: ["January", "February", "March", "April", "May", "June", "July"],
|
|
|
|
datasets: [{
|
|
|
|
label: "My First dataset",
|
|
|
|
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
|
|
|
|
}, {
|
|
|
|
label: "My Second dataset",
|
|
|
|
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
|
|
|
|
}]
|
|
|
|
};
|
2014-06-29 19:36:04 +02:00
|
|
|
|
2015-05-16 04:54:01 +02:00
|
|
|
$.each(lineChartData.datasets, function(i, dataset) {
|
|
|
|
dataset.borderColor = randomColor(0.4);
|
2015-05-20 09:03:45 +02:00
|
|
|
dataset.backgroundColor = randomColor(1);
|
2015-05-16 04:54:01 +02:00
|
|
|
dataset.pointBorderColor = randomColor(0.7);
|
|
|
|
dataset.pointBackgroundColor = randomColor(0.5);
|
|
|
|
dataset.pointBorderWidth = 1;
|
|
|
|
});
|
2015-05-16 00:40:01 +02:00
|
|
|
|
2015-05-16 04:54:01 +02:00
|
|
|
console.log(lineChartData);
|
2013-03-18 00:57:50 +01:00
|
|
|
|
2015-05-16 04:54:01 +02:00
|
|
|
window.onload = function() {
|
|
|
|
var ctx = document.getElementById("canvas").getContext("2d");
|
2015-05-20 15:03:22 +02:00
|
|
|
window.myLine = new Chart(ctx).Line({
|
|
|
|
data: lineChartData,
|
|
|
|
options: {
|
|
|
|
responsive: true,
|
|
|
|
hoverMode: 'label',
|
|
|
|
stacked: true
|
|
|
|
}
|
2015-05-16 04:54:01 +02:00
|
|
|
});
|
|
|
|
};
|
2014-06-29 19:36:04 +02:00
|
|
|
|
2015-05-16 04:54:01 +02:00
|
|
|
$('#randomizeData').click(function() {
|
|
|
|
lineChartData.datasets[0].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()];
|
2015-01-08 18:13:14 +01:00
|
|
|
|
2015-05-16 04:54:01 +02:00
|
|
|
lineChartData.datasets[1].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()];
|
2015-01-08 18:13:14 +01:00
|
|
|
|
2015-05-16 04:54:01 +02:00
|
|
|
window.myLine.update();
|
2015-01-08 18:13:14 +01:00
|
|
|
});
|
2015-05-16 04:54:01 +02:00
|
|
|
</script>
|
|
|
|
</body>
|
2015-01-08 18:13:14 +01:00
|
|
|
|
2013-03-18 00:57:50 +01:00
|
|
|
</html>
|