Chart.js/samples/doughnut.html
Evert Timberg 12e2ace039 Merge remote-tracking branch 'upstream/v2.0-dev' into feature/v2.0dev-xy
Conflicts:
	src/Chart.Core.js

Fixed the sample files & chart type initialize methods so that this.data does not get set to undefined.
2015-05-20 09:03:22 -04:00

80 lines
2.1 KiB
HTML

<!doctype html>
<html>
<head>
<title>Doughnut Chart</title>
<script src="../Chart.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<style>
body {
padding: 0;
margin: 0;
}
#canvas-holder {
width: 30%;
}
</style>
</head>
<body>
<div id="canvas-holder" style="width:100%">
<canvas id="chart-area" width="500" height="500" />
</div>
<button id="randomizeData">Randomize Data</button>
<script>
var randomScalingFactor = function() {
return Math.round(Math.random() * 100)
};
var randomColorFactor = function() {
return Math.round(Math.random() * 255)
};
var doughnutData = {
data: [{
value: randomScalingFactor(),
backgroundColor: "#F7464A",
label: "Red"
}, {
value: randomScalingFactor(),
backgroundColor: "#46BFBD",
label: "Green"
}, {
value: randomScalingFactor(),
backgroundColor: "#FDB45C",
label: "Yellow"
}, {
value: randomScalingFactor(),
backgroundColor: "#949FB1",
label: "Grey"
}, {
value: randomScalingFactor(),
backgroundColor: "#4D5360",
label: "Dark Grey"
}
]
};
window.onload = function() {
var ctx = document.getElementById("chart-area").getContext("2d");
window.myDoughnut = new Chart(ctx).Doughnut({
data: doughnutData,
options: {
responsive: true
}
});
};
$('#randomizeData').click(function() {
$.each(doughnutData.data, function(i, datapoint) {
datapoint.value = randomScalingFactor();
datapoint.backgroundColor = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
});
window.myDoughnut.update();
});
</script>
</body>
</html>