From 1968b598a447754ca010c0652acce1ffeb70caa4 Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Sun, 29 May 2016 21:52:01 +0100 Subject: [PATCH] Fixed pie slices colour range limited to 15, now random (#603) --- application/views/reports/graphs/pie.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/application/views/reports/graphs/pie.php b/application/views/reports/graphs/pie.php index a89552247..cfb4de336 100644 --- a/application/views/reports/graphs/pie.php +++ b/application/views/reports/graphs/pie.php @@ -70,5 +70,18 @@ }]*/ ]; - new Chartist.Pie('#chart1', data, options, responsiveOptions); + chart = new Chartist.Pie('#chart1', data, options, responsiveOptions); + + // generate random colours for the pie sliced because Chartist is currently limited to 15 colours + chart.on('draw', function(data) { + if(data.type === 'slice') { + var r = Math.floor(Math.random() * 256); + var g = Math.floor(Math.random() * 256); + var b = Math.floor(Math.random() * 256); + + data.element.attr({ + style: 'fill: #' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1) + }); + } + }); \ No newline at end of file