Stacked bars in Grafana for multiple tables

In FluxDB I have data with 1 tag and two fields:

_time     _measurement  available (field) sold (field)	country (tag)
20200401  apples        20				  80			UK
20200401  apples        30				  20			Holland

Now, in Grafana I would like to create stacked bar plot, where:

  • available and sold fields are stacked together
  • I still can choose between different countries

If I limit my query to a single country only:

from(bucket: "products")
  |> range(start: 2020-04-01T00:00:00Z)
  |> filter(fn: (r) =>
    r._measurement == "apples"  and
    r.country == "UK" and
    (r._field == "available" or r._field == "sold")
  ) 

this works pretty well, because I got two tables and for each table there is one series of bars:

  • available(country=UK)
  • sold(country=UK)

However, if I do not fix the country:

from(bucket: "products")
  |> range(start: 2020-04-01T00:00:00Z)
  |> filter(fn: (r) =>
    r._measurement == "apples"  and
    (r._field == "available" or r._field == "sold")
  ) 

I get multiple tables displayed all together

  • vailable(country=UK)
  • sold(country=UK)
  • available(country=US)
  • sold(country=US)

and I need to manually select (Ctrl+mouse click) pairs of tables I want to display at the moment, while I would like to be able to select “country” and stacked bars for the selected country should show up.

I guess Grafana is not the right solution for what I want and the only solution is to create multiple panels/plots, each for different country, right?

The solution I’ve found in the meantime is to use template variables, that let me choose the culture I want to display.

1 Like

Hello!
We are glad you were able to solve the issue and are able to use Grafana. Thank you for sharing the workaround.

This topic was automatically closed after 365 days. New replies are no longer allowed.