Skip to content

Instantly share code, notes, and snippets.

@jmevalentin
Created December 5, 2019 05:02
Show Gist options
  • Save jmevalentin/3473fc14ab7fae00de0d892af782caa4 to your computer and use it in GitHub Desktop.
Save jmevalentin/3473fc14ab7fae00de0d892af782caa4 to your computer and use it in GitHub Desktop.
Pie chart creation with images overlaying the slices
/*
The goal of this script is to generate a donut chart with images overlaying the slices
(or possibly extending from them like tooltips). The images will be named similar to the
slice label
*/
var objs_feed = drupalSettings.objectives;
var objectives = [
['Status', 'Amount']
];
var counts = {};
$.each(objs_feed, function(key,value) {
counts[value.field_objective_status] = (counts[value.field_objective_status] || 0)+1;
});
$.each(counts, function(k, v) {
objectives.push([
k, v
]);
});
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(function() { drawChart(objectives); });
function drawChart(objectiveData) {
var data = google.visualization.arrayToDataTable(objectiveData);
console.dir(data);
// NOTE: the `pieSliceText: 'label'` option seemsto have no effect
var options = {
legend: 'none',
title: 'Objectives',
pieSliceText: 'label',
pieHole: 0.4,
};
var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
chart.draw(data, options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment