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>
|
2015-06-12 22:00:48 +02:00
|
|
|
<div style="width:300px;height:30px">
|
|
|
|
<canvas id="canvas" style="width:100%;height:100%"></canvas>
|
2015-05-16 04:54:01 +02:00
|
|
|
</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-06-02 23:14:06 +02:00
|
|
|
var config = {
|
|
|
|
data: {
|
|
|
|
labels: ["January", "February", "March", "April", "May", "June", "July"],
|
|
|
|
datasets: [{
|
|
|
|
label: "My First dataset",
|
|
|
|
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
|
|
|
|
fill: false,
|
|
|
|
}, {
|
|
|
|
label: "My Second dataset",
|
|
|
|
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
options: {
|
2015-06-12 22:00:48 +02:00
|
|
|
responsive: true,
|
|
|
|
scales: {
|
|
|
|
xAxes: [{
|
|
|
|
display: false
|
|
|
|
}],
|
|
|
|
yAxes: [{
|
|
|
|
display: false
|
|
|
|
}]
|
|
|
|
}
|
2015-06-02 23:14:06 +02:00
|
|
|
}
|
2015-05-16 04:54:01 +02:00
|
|
|
};
|
2014-06-29 19:36:04 +02:00
|
|
|
|
2015-06-02 23:14:06 +02:00
|
|
|
$.each(config.data.datasets, function(i, dataset) {
|
2015-05-16 04:54:01 +02:00
|
|
|
dataset.borderColor = randomColor(0.4);
|
2015-05-31 22:55:17 +02:00
|
|
|
dataset.backgroundColor = randomColor(0.5);
|
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-06-02 23:14:06 +02:00
|
|
|
console.log(config.data);
|
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-06-02 23:14:06 +02:00
|
|
|
window.myLine = new Chart(ctx).Line(config);
|
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() {
|
2015-06-02 23:14:06 +02:00
|
|
|
config.data.datasets[0].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()];
|
2015-01-08 18:13:14 +01:00
|
|
|
|
2015-06-02 23:14:06 +02:00
|
|
|
config.data.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>
|