Updated Samples

Samples now include a “Randomize Data” button which utilizes the latest
changes.
This commit is contained in:
Tanner Linsley 2015-01-08 10:13:14 -07:00
parent 359e94151c
commit 026611110a
8 changed files with 99 additions and 26 deletions

View File

@ -3,15 +3,17 @@
<head>
<title>Bar Chart</title>
<script src="../Chart.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<div style="width: 50%">
<canvas id="canvas" height="450" width="600"></canvas>
</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 barChartData = {
labels : ["January","February","March","April","May","June","July"],
@ -40,6 +42,16 @@
});
}
$('#randomizeData').click(function(){
barChartData.datasets[0].fillColor = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
barChartData.datasets[0].data = [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()];
barChartData.datasets[1].fillColor = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
barChartData.datasets[1].data = [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()];
window.myBar.update();
});
</script>
</body>
</html>

View File

@ -3,6 +3,7 @@
<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;
@ -17,37 +18,41 @@
<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: 300,
value: randomScalingFactor(),
color:"#F7464A",
highlight: "#FF5A5E",
label: "Red"
},
{
value: 50,
value: randomScalingFactor(),
color: "#46BFBD",
highlight: "#5AD3D1",
label: "Green"
},
{
value: 100,
value: randomScalingFactor(),
color: "#FDB45C",
highlight: "#FFC870",
label: "Yellow"
},
{
value: 40,
value: randomScalingFactor(),
color: "#949FB1",
highlight: "#A8B3C5",
label: "Grey"
},
{
value: 120,
value: randomScalingFactor(),
color: "#4D5360",
highlight: "#616774",
label: "Dark Grey"
@ -60,6 +65,14 @@
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();
});
</script>

View File

@ -3,6 +3,7 @@
<head>
<title>Line Chart</title>
<script src="../Chart.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<div style="width:30%">
@ -10,10 +11,13 @@
<canvas id="canvas" height="450" width="600"></canvas>
</div>
</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 lineChartData = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
@ -48,6 +52,16 @@
});
}
$('#randomizeData').click(function(){
lineChartData.datasets[0].fillColor = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.3)';
lineChartData.datasets[0].data = [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()];
lineChartData.datasets[1].fillColor = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.3)';
lineChartData.datasets[1].data = [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()];
window.myLine.update();
});
</script>
</body>

View File

@ -3,42 +3,46 @@
<head>
<title>Pie Chart</title>
<script src="../Chart.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<div id="canvas-holder">
<canvas id="chart-area" width="300" height="300"/>
</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 pieData = [
{
value: 300,
value: randomScalingFactor(),
color:"#F7464A",
highlight: "#FF5A5E",
label: "Red"
},
{
value: 50,
value: randomScalingFactor(),
color: "#46BFBD",
highlight: "#5AD3D1",
label: "Green"
},
{
value: 100,
value: randomScalingFactor(),
color: "#FDB45C",
highlight: "#FFC870",
label: "Yellow"
},
{
value: 40,
value: randomScalingFactor(),
color: "#949FB1",
highlight: "#A8B3C5",
label: "Grey"
},
{
value: 120,
value: randomScalingFactor(),
color: "#4D5360",
highlight: "#616774",
label: "Dark Grey"
@ -51,6 +55,14 @@
window.myPie = new Chart(ctx).Pie(pieData);
};
$('#randomizeData').click(function(){
$.each(pieData, function(i, piece){
pieData[i].value = randomScalingFactor();
pieData[i].color = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
});
window.myPie.update();
});
</script>

View File

@ -3,42 +3,47 @@
<head>
<title>Polar Area Chart</title>
<script src="../Chart.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<div id="canvas-holder" style="width:30%">
<canvas id="chart-area" width="300" height="300"/>
</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 polarData = [
{
value: 300,
value: randomScalingFactor(),
color:"#F7464A",
highlight: "#FF5A5E",
label: "Red"
},
{
value: 50,
value: randomScalingFactor(),
color: "#46BFBD",
highlight: "#5AD3D1",
label: "Green"
},
{
value: 100,
value: randomScalingFactor(),
color: "#FDB45C",
highlight: "#FFC870",
label: "Yellow"
},
{
value: 40,
value: randomScalingFactor(),
color: "#949FB1",
highlight: "#A8B3C5",
label: "Grey"
},
{
value: 120,
value: randomScalingFactor(),
color: "#4D5360",
highlight: "#616774",
label: "Dark Grey"
@ -53,6 +58,14 @@
});
};
$('#randomizeData').click(function(){
$.each(polarData, function(i, piece){
polarData[i].value = randomScalingFactor();
polarData[i].color = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
});
window.myPolarArea.update();
});
</script>

View File

@ -3,19 +3,20 @@
<head>
<title>Radar Chart</title>
<script src="../Chart.js"></script>
<meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
<style>
canvas{
}
</style>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<div style="width:30%">
<canvas id="canvas" height="450" width="450"></canvas>
</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 radarChartData = {
labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
datasets: [
@ -27,7 +28,7 @@
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [65,59,90,81,56,55,40]
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
},
{
label: "My Second dataset",
@ -37,7 +38,7 @@
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [28,48,40,19,96,27,100]
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
}
]
};
@ -48,6 +49,16 @@
});
}
$('#randomizeData').click(function(){
radarChartData.datasets[0].fillColor = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.3)';
radarChartData.datasets[0].data = [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()];
radarChartData.datasets[1].fillColor = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.3)';
radarChartData.datasets[1].data = [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()];
window.myRadar.update();
});
</script>
</body>
</html>

View File

@ -135,7 +135,6 @@
label : segment.label
});
}, this);
console.log(this.data, this.segments);
} else{
// Data size changed without properly inserting, just redraw the chart
this.initialize(this.data);

View File

@ -204,7 +204,6 @@
value: segment.value,
});
},this);
console.log(this.data, this.segments);
} else{
// Data size changed without properly inserting, just redraw the chart
this.initialize(this.data);