order groups in stacked bars chart
Does anyone know how to change the order of the groups in a stacked bar chart? I want my bars ordered so that the group that is the largest is on the bottom of the bar. Is this possible without custom d3?
You can achieve the results that you are looking for by using the rank function in SQL. I've attached a working example where I use the rank function, then concat the rank to the value that I want to order by in the stacked bar chart.
SELECT *, RANK() over (ORDER BY pop DESC) || '-' || city AS rnk FROM ( SELECT SUM(population_estimate_2012) AS pop, city, state FROM tutorial.city_populations WHERE state = 'CA' GROUP BY state, city ) sub_query