Skip to content

Instantly share code, notes, and snippets.

@hughevans
Last active December 15, 2015 13:29
Show Gist options
  • Select an option

  • Save hughevans/5267912 to your computer and use it in GitHub Desktop.

Select an option

Save hughevans/5267912 to your computer and use it in GitHub Desktop.
drawChart = function(chapters) {
var data = {
// Create the dataset objects required for Chart.js
datasets: $.map(chapters, function(chapter, index) {
// Different shades of blue/green for each of the nine chapters
var red = 26;
var green = 67 + (16 * index);
var blue = 84 + (13 * index);
var colour = red + "," + green + "," + blue;
return {
fillColor: "rgba("+colour+",0.8)",
strokeColor: "rgba("+colour+",0.9)",
pointColor: "rgba("+colour+",0)",
pointStrokeColor: "rgba("+colour+",0)",
// The Chart.js radar chart is not stacked so we add the total of the previous
// chapters’ words to this one to make it so
data: $.map(chapter, function(segment, segmentIndex) {
var otherTotal = 0;
for (var i=8; i > index; i--) {
otherTotal = otherTotal + chapters[i][segmentIndex];
}
return otherTotal + segment;
})
};
})
};
var ctx = $("#radar_chart").get(0).getContext("2d");
new Chart(ctx).Radar(data, {scaleLineColor : "rgba(0,0,0,.06)"});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment