forked from chartjs/Chart.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Group stacked bar charts (chartjs#2643) (chartjs#3563)
Group stacked bar charts (chartjs#2643)
- Loading branch information
1 parent
0bf2076
commit 2d4a6a6
Showing
6 changed files
with
1,045 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<!doctype html> | ||
<html> | ||
|
||
<head> | ||
<title>Stacked Bar Chart with Groups</title> | ||
<script src="../../dist/Chart.bundle.js"></script> | ||
<script src="../utils.js"></script> | ||
<style> | ||
canvas { | ||
-moz-user-select: none; | ||
-webkit-user-select: none; | ||
-ms-user-select: none; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div style="width: 75%"> | ||
<canvas id="canvas"></canvas> | ||
</div> | ||
<button id="randomizeData">Randomize Data</button> | ||
<script> | ||
var barChartData = { | ||
labels: ["January", "February", "March", "April", "May", "June", "July"], | ||
datasets: [{ | ||
label: 'Dataset 1', | ||
backgroundColor: window.chartColors.red, | ||
stack: 'Stack 0', | ||
data: [ | ||
randomScalingFactor(), | ||
randomScalingFactor(), | ||
randomScalingFactor(), | ||
randomScalingFactor(), | ||
randomScalingFactor(), | ||
randomScalingFactor(), | ||
randomScalingFactor() | ||
] | ||
}, { | ||
label: 'Dataset 2', | ||
backgroundColor: window.chartColors.blue, | ||
stack: 'Stack 0', | ||
data: [ | ||
randomScalingFactor(), | ||
randomScalingFactor(), | ||
randomScalingFactor(), | ||
randomScalingFactor(), | ||
randomScalingFactor(), | ||
randomScalingFactor(), | ||
randomScalingFactor() | ||
] | ||
}, { | ||
label: 'Dataset 3', | ||
backgroundColor: window.chartColors.green, | ||
stack: 'Stack 1', | ||
data: [ | ||
randomScalingFactor(), | ||
randomScalingFactor(), | ||
randomScalingFactor(), | ||
randomScalingFactor(), | ||
randomScalingFactor(), | ||
randomScalingFactor(), | ||
randomScalingFactor() | ||
] | ||
}] | ||
|
||
}; | ||
window.onload = function() { | ||
var ctx = document.getElementById("canvas").getContext("2d"); | ||
window.myBar = new Chart(ctx, { | ||
type: 'bar', | ||
data: barChartData, | ||
options: { | ||
title:{ | ||
display:true, | ||
text:"Chart.js Bar Chart - Stacked" | ||
}, | ||
tooltips: { | ||
mode: 'index', | ||
intersect: false | ||
}, | ||
responsive: true, | ||
scales: { | ||
xAxes: [{ | ||
stacked: true, | ||
}], | ||
yAxes: [{ | ||
stacked: true | ||
}] | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
document.getElementById('randomizeData').addEventListener('click', function() { | ||
barChartData.datasets.forEach(function(dataset, i) { | ||
dataset.data = dataset.data.map(function() { | ||
return randomScalingFactor(); | ||
}); | ||
}); | ||
window.myBar.update(); | ||
}); | ||
</script> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.