Chart.js/samples/line.html

81 lines
2.7 KiB
HTML
Raw Normal View History

<!doctype html>
<html>
<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-06-12 22:48:20 +02:00
<style>
canvas {
-webkit-box-shadow: 0 0 20px 0 rgba(0, 0, 0, .5);
}
</style>
</head>
<body>
<div style="width:50%;">
2015-06-12 22:00:48 +02:00
<canvas id="canvas" style="width:100%;height:100%"></canvas>
</div>
2015-06-12 22:48:20 +02:00
<br>
<br>
<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));
};
var randomColor = function(opacity) {
return 'rgba(' + Math.round(Math.random() * 255) + ',' + Math.round(Math.random() * 255) + ',' + Math.round(Math.random() * 255) + ',' + (opacity || '.3') + ')';
};
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: true
2015-06-12 22:00:48 +02:00
}],
yAxes: [{
display: true
2015-06-12 22:00:48 +02:00
}]
}
2015-06-02 23:14:06 +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) {
dataset.borderColor = randomColor(0.4);
dataset.backgroundColor = randomColor(0.5);
dataset.pointBorderColor = randomColor(0.7);
dataset.pointBackgroundColor = randomColor(0.5);
dataset.pointBorderWidth = 1;
});
2015-06-02 23:14:06 +02:00
console.log(config.data);
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);
};
2014-06-29 19:36:04 +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-06-02 23:14:06 +02:00
config.data.datasets[1].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()];
window.myLine.update();
});
</script>
</body>
</html>