superset icon indicating copy to clipboard operation
superset copied to clipboard

Ordering on X axis on the distribution bar chart

Open Frituurpanda opened this issue 10 years ago • 24 comments

Hi all,

I have a very simple question that i'm almost embarrassed to ask. I'm not sure how to order on the X axis in Caravel. It is possible to for instance group by certain names and that works fine. Now however, where trying to group by a certain scale.

You can view the problem here: screen shot 2016-05-26 at 11 32 25

We now grouped the results in this test based on the scalelevel, which is a integer value. Is it possible to order those results from zero to eighteen (or any kind or sort)?

Thanks in advance for any kind of help, you guys have been amazing!

Frituurpanda avatar May 26 '16 09:05 Frituurpanda

+1 for this and #525, currently I manually create an extremely small 'order by' metric as the 1st metric... but would be nice to be able to specify one

verydxz avatar Jun 05 '16 01:06 verydxz

Hi verydxz,

Thanks for the answer, could you maybe give an example of how you implemented this? When looking at the screenshot further up, you'll see that the X axis actually has important values in there. The 0 > 18 references to the scalelevel in this domain. The Y axis refers to a simple count.

You said that you create a extremely small order by metric as the first metric. If i'd add a small order by in the series, i'd lose the values that I have in the X axis right?

Frituurpanda avatar Jun 06 '16 08:06 Frituurpanda

I managed to create the 'order by' metric but had the same issue as @Frituurpanda that I lost the values that I actually wanted to have on the x axis

katemarielewis avatar Jul 11 '16 22:07 katemarielewis

We're having the same issue, anyone has any updates on this?

mrbungie avatar Aug 01 '16 16:08 mrbungie

At this point i still don't have a good solution to this. Aside from using a small custom metric in the database. That's not a good solution though since you'll have to add that for every usecase manually..

Frituurpanda avatar Aug 03 '16 06:08 Frituurpanda

https://github.com/airbnb/caravel/pull/1379

vera-liu avatar Oct 24 '16 16:10 vera-liu

Please, reopen this issue as it is not solved. After #1379, labels are sorted only alphabetically. In case of numeric labels the resulting order is wrong, e.g. 1, 10, 2, 21, 3 instead of 1, 2, 3, 10, 21.

ondrejkopicka avatar Mar 30 '17 09:03 ondrejkopicka

True, have worked around this issue by setting a custom metric in the database to sort based on that. Not really a scaleable solution but it works for my usecase..

Frituurpanda avatar Mar 30 '17 09:03 Frituurpanda

I have the same problem.

suuuch avatar Jun 21 '17 13:06 suuuch

@Frituurpanda @vera-liu I also have the same problem.

Hackeruncle avatar Jul 01 '17 06:07 Hackeruncle

I got the same problem @vera-liu

harryprince avatar Sep 29 '17 13:09 harryprince

Still an issue, and with the limitation of running multiple queries (creating temp tables and then selecting from them) being an issue, read: it doesn't work - this is an issue.

vtyr avatar Oct 03 '17 08:10 vtyr

I could do it selecting the option "Sort Bars"

image

iasmini avatar Jan 26 '18 13:01 iasmini

@iasmini What's the plot you selected? What release of superset are you using? In Distribution - Bar Chart I can't see any of the fields your screenshot shows!

Thank you :-)

CriMenghini avatar Feb 28 '18 14:02 CriMenghini

@CriMenghini

Version: {"GIT_SHA": "", "version": "0.17.1"}

image

iasmini avatar Feb 28 '18 18:02 iasmini

For me it still does only sort alphabetically.

"version": "0.24.0"

For example: it does not work when ordering months given as strings or numbers.

I think it would be a great improvement to customize the exact column order manually or even change the column labels.

benkindt avatar Apr 25 '18 11:04 benkindt

I could do it selecting the option "Sort Bars"

image

This worked for me, thanks!

ariasjose avatar Feb 22 '19 22:02 ariasjose

Screenshot 2019-07-05 at 12 36 04 I don't know if it is still useful or not, but I did it by setting the value of "order_bars" to true, in the "Parameters" of the edit chart part of my "Distribution bar chart" instance.

rzeAkbari avatar Jul 05 '19 10:07 rzeAkbari

sorting the chart based on time 00:00 AM ,01:00 AM ,02:00 AM ,03:00AM

if(fd.order_time){ data.forEach((d) => { d.values.sort(function(a,b){return new Date('1970/01/01 ' + a.x) - new Date('1970/01/01 ' + b.x)}); }); new time chronological order

sorting the chart based on time "January", "February", "March", "April", var months = ["January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"];

        data.forEach((d) => { console.log(d.values);
        d.values.sort(function(a, b){ return months.indexOf(a.x) - months.indexOf(b.x); });
        });  

Note: we can arrange it in what a custom order we want

kalimuthu123 avatar Dec 20 '19 09:12 kalimuthu123

I am facing same issue now with Superset 1.0.1 and Bar Chart (cannot find Distributed Bar Chart any more. There is no option to Sort Bars in Bar Chart - how to make the bars sorted by x axis label instead of metric value?

michalrudko avatar Mar 22 '21 23:03 michalrudko