3

I have a bar chart in Superset where I have two different columns configured under BREAKDOWN. Both columns divide the data into two parts, so I end up with four different breakdowns. Example: I have sales data for two different cities, and the sales data are broken down by product (2 different products).

I would like to compare sales between the cities, so I would like to group the one column (sales). However, for each city I want to add up total sales by adding both products, so I would like to stack those bars.

So far, I can only find a way to EITHER stack or group the bars, which gives me either four bars per month, or a single bar - neither of which is useful. Is there a way to have a chart that is both grouped and stacked at the same time depending on the column used for the breakdown?

This is what it looks like now:

Stacked columns

Grouped columns

1 Answers1

2

Unfortunately right now it is impossible to do with the Timeseries charts. Even when using mixed Timeseries when both of the charts are Bar charts when they are stacked, they will stack together.

There is one workaround that could help you with achieving this goal.

You need to use Bar Chart

enter image description here

Here I just have some dummy data with sales_date, product, city and sales

As a first dimension I set

DATE_TRUNC('month', sales_date)::date

as I want to have sales grouped by month. As a second dimension I've just set city

When it comes to breakdown you can simply add product as a breakdown but I've set

(product || ', ' || city)

so it can be treaded as different labels and therefore it is more readable on chart.

At the end since Bar chart doesn't understand that it need to be sorted by date. In a field sort by I've set

(DATE_TRUNC('month', sales_date)::date)::text || city

and and set to be sorted ascending After doing all that go to CUSTOMIZE options and set chart to have STACKED BARS

This is a workaround by using only Superset's charts.

puchal
  • 1,883
  • 13
  • 25
  • Thanks so much, this looks like an interesting workaround. I will be trying this out and will report back. –  Feb 24 '23 at 11:49
  • Would there be any way to have some space between each month (so two bars, space, two bars, space, etc), like in the original charts? –  Feb 24 '23 at 11:51
  • @user74934 I don't believe so, as this chart (or any chart in superset) doesn't have that much flexibility in utilising all options of the charts. I believe that it would be the best if you wrote custom chart for that case. Maybe it could work if you add another "dummy" empty string `city` for each of the month. Then there will be a gap as there should be a bar chart but it will have empty data. Though it makes it more of a mess from the chart at that time. – puchal Feb 24 '23 at 12:49
  • @user74934 since `Bar Chart` is not an EChart but chart created by html elements, maybe you could manipulate it with CSS to achieve spaces between bars – puchal Feb 24 '23 at 12:54