Bar chart stacking - what am I missing?

  • What Grafana version and what operating system are you using?
    Windows 11, Grafana 10.1.4

  • What are you trying to achieve?
    I am trying to display the content of multiple storages containing different items/articles with different amounts.
    In the result I want to display one bar per storage which shows the articles which are stored to this storage with a different color, a corresponding size (according to the amount of items stored) and it should be stacked

  • How are you trying to achieve it?
    I am using bar chart panel and an SQL query which groups data according to storage and article/item:

And I am assigning the storage name to x-axis as well as selecting the normal stack option and setting “color by field” to the article number “ArtNr”.

  • What happened?
    The data itself seems to be correct, but I get multiple bar charts for a single storage:

  • What did you expect to happen?
    I want one bar per storage - see all bars within the red marked rectangle. They should be stacked and after that the next storage shold be one bar.

  • Can you copy/paste the configuration(s) that you are having problems with?
    See SQL query and config. If anything else is needed, I will be happy to provice it.

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    No

  • Did you follow any online instructions? If so, what is the URL?
    I have tried using ChatGPT before which only gave me useless advice. I have also tried to do some data transformation, without any good result.

What am I missing? It has to be something stupid :-/

Thanks for your help!!

can you drop a sanitized csv of your data?

Hello!

I do not know exactly what you mean with “sanitized” but I just used to embedded CSV export.
IMHO the data looks ok. Since csv Upload is not allowed, I send you a screenshot at the raw data:

“Storage”,“ArtNr”,“Amount”
TR || EG || 01 || 01 || ,20.398,190
TR || EG || 01 || 01 || ,60.155,50
TR || EG || 01 || 01 || ,C20-LEAF,288
TR || EG || 01 || 01 || ,CA20034RC,276
TR || EG || 01 || 01 || ,ELGS,6.768
TR || EG || 01 || 01 || ,GDM15-1,2.640
TR || EG || 01 || 01 || ,GDM15-2,4
TR || EG || 01 || 01 || ,HA20008,292
TR || EG || 01 || 01 || ,LL1311S,1.500
TR || EG || 01 || 01 || ,LL141705,1.500
TR || EG || 01 || 01 || ,LL17013,1.509
TR || EG || 01 || 01 || ,LL17037,2.500
TR || EG || 01 || 01 || ,LL17037EU,800
TR || EG || 01 || 01 || ,LL18029,504
TR || EG || 01 || 01 || ,LL19011,6
TR || EG || 01 || 01 || ,LL19019,504
TR || EG || 01 || 01 || ,LL19061,1.008
TR || EG || 01 || 01 || ,Ne_GDM15-2,1.620
TR || EG || 01 || 01 || ,PL18029EU,1.008
TR || EG || 01 || 01 || ,SL16009,1.000
TR || EG || 01 || 01 || ,SL17009,504
TR || EG || 01 || 01 || ,SL18007,408
TR || EG || 01 || 01 || ,SL19022,252
TR || EG || 01 || 01 || ,SL20015,312
TR || EG || 01 || 01 || ,SL20018,228
TR || EG || 01 || 01 || ,SL200YWC,156
TR || EG || 01 || 01 || ,XM-PARTY30-M-EURO,2.504
TR || EG || 01 || 02 || ,20.398,56
TR || EG || 01 || 02 || ,60.155,1
TR || EG || 01 || 02 || ,895.721,72
TR || EG || 01 || 02 || ,GDM15-2,102
TR || EG || 01 || 02 || ,LL17013,346

Thank you!

The first column is a concatenated string. Maybe it’s necessary to put it in quotes?

That does not seem to change anything…

1 Like

OK, this seem to solve the problem of the stacking.
Can you shortly explain to me, why transformation is necessary as all the data has been provided properly by the SQL statement?
Additionally I want to display the name of the item/article (ArtNr) in the tooltip and therefore replace the iterating numbers with the item specific amounts.
Do I need additional transformation steps for that too?

grafana expects one name with multiple values, not multiples of the same name…

check out an example of how the data should look:

https://play.grafana.org/d/timeseries-stacking2/timeseries-and-barchart-stacking?orgId=1&from=2021-12-14T04:26:06.000Z&to=2022-01-19T08:44:05.000Z&timezone=utc&editPanel=17

it’s a little harder to add the tooltip as well

I guess, I need to dive more into data transformation and the prerequisites of the bar chart.
I expected this task to be implemented way easier :-/

Thanks for the information and your help!!

1 Like