From c4ff05b1bac6cc12515f20a9aaaeececd8067c29 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 14 Jul 2017 17:21:30 +0200 Subject: [PATCH] Sort fix #698 [skip ci] --- app/Generator/Chart/Basic/ChartJsGenerator.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Generator/Chart/Basic/ChartJsGenerator.php b/app/Generator/Chart/Basic/ChartJsGenerator.php index 4649e0722d..4112e41d36 100644 --- a/app/Generator/Chart/Basic/ChartJsGenerator.php +++ b/app/Generator/Chart/Basic/ChartJsGenerator.php @@ -110,7 +110,12 @@ class ChartJsGenerator implements GeneratorInterface ]; // sort by value, keep keys. + // different sort when values are positive and when they're negative. asort($data); + if(bccomp(next($data),'0') === 1) { + // next is positive, sort other way around. + arsort($data); + } $index = 0; foreach ($data as $key => $value) {