Chart.js/samples/doughnut.html

81 lines
1.7 KiB
HTML
Raw Normal View History

<!doctype html>
<html>
<head>
<title>Doughnut Chart</title>
2013-03-25 20:25:57 +01:00
<script src="../Chart.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<style>
2014-06-29 19:36:04 +02:00
body{
padding: 0;
margin: 0;
}
#canvas-holder{
width:30%;
}
</style>
</head>
<body>
2014-06-29 19:36:04 +02:00
<div id="canvas-holder">
<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 = [
{
value: randomScalingFactor(),
2014-06-29 19:36:04 +02:00
color:"#F7464A",
highlight: "#FF5A5E",
label: "Red"
},
{
value: randomScalingFactor(),
2014-06-29 19:36:04 +02:00
color: "#46BFBD",
highlight: "#5AD3D1",
label: "Green"
},
{
value: randomScalingFactor(),
2014-06-29 19:36:04 +02:00
color: "#FDB45C",
highlight: "#FFC870",
label: "Yellow"
},
{
value: randomScalingFactor(),
2014-06-29 19:36:04 +02:00
color: "#949FB1",
highlight: "#A8B3C5",
label: "Grey"
},
{
value: randomScalingFactor(),
2014-06-29 19:36:04 +02:00
color: "#4D5360",
highlight: "#616774",
label: "Dark Grey"
}
2014-06-29 19:36:04 +02:00
];
2014-06-29 19:36:04 +02:00
window.onload = function(){
var ctx = document.getElementById("chart-area").getContext("2d");
window.myDoughnut = new Chart(ctx).Doughnut(doughnutData, {responsive : true});
};
$('#randomizeData').click(function(){
$.each(doughnutData, function(i, piece){
doughnutData[i].value = randomScalingFactor();
doughnutData[i].color = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
});
window.myDoughnut.update();
});
2014-06-29 19:36:04 +02:00
</script>
</body>
</html>