Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
The problem
When grouping the results (i.e., in Charts lingo, having more than one series) and some series don't have all the data points, the output will be wrong, since values per series will just be added sequentially from the "right", through the following line (which doesn't take the "label key" into account at all):
$chart[$series_key]['#data'][] = $value;
An example
You want to show a column chart of the GPD of two countries, A and B, for the years 2012–2014, but country B hasn't reported a value for the year 2013:
Country | Year | GPD
---------------------
A | 2012 | 8 T$
A | 2013 | 9 T$
A | 2014 | 10 T$
B | 2012 | 3 T$
B | 2014 | 5 T$
This will lead to the following output:
As you can see, the value for B/2014 ends up as the 2013 value instead.
Comment | File | Size | Author |
---|---|---|---|
#7 | 2629018-7--grouped_incomplete_results.patch | 2.71 KB | Elin Yordanov |
#5 | Column chart after patch.png | 68.94 KB | davidkp |
#5 | Column chart before patch.png | 108.12 KB | davidkp |
#3 | 2629018-3--grouped_incomplete_results.patch | 2.55 KB | drunken monkey |
#3 | 2629018-3--grouped_incomplete_results--interdiff.txt | 697 bytes | drunken monkey |
Comments
Comment #2
drunken monkeyThe attached patch fixes the problem for me, and will also correct the group labels if the first series doesn't have all values.
Please tell me what you think!
Comment #3
drunken monkeyEmpty values should default to
NULL
, not''
, otherwise Highcharts will produce weird results (line diagrams with unconnected points, for example).Comment #4
herd45 CreditAttribution: herd45 as a volunteer commentedI've tested and this works as expected
Comment #5
davidkp CreditAttribution: davidkp as a volunteer commentedThanks for posting this patch but alas it did not work for me with the latest dev version released a couple of days ago.
After applying the patch I get the following error 'Data column(s) for axis #0 cannot be of type string'.
Please see the attached before and after images of my column chart including a table with the data.
Comment #6
Elin Yordanov CreditAttribution: Elin Yordanov commentedThank you drunken monkey, re-rolled the patch to the current dev version. It works for me. Please review.
I also go ahead and put the priority of this issue to major.
Comment #7
Elin Yordanov CreditAttribution: Elin Yordanov commentedThe previous patch has broken the sorting. Removing the line with ksort() fixes this too. Please review the attached patch.
Comment #8
joseph.olstadThis issue has a duplicate issue:
#3078113: Fix grouped labels
I am not sure which solution is better, 3078113 or this one
In either case, it would be nice to have one of the two solutions committed and released.
Thanks!