Percentages of a few data streams , cant manage to display it into a correct (stacked) bar graph

I have a few data streams that display percentages, but I can’t get it neatly into a stacked bar chart.
can someone help please?
so what I want to achieve is a bar chart, which shows the percentages per day. which can go up to 100% in total.

from(bucket: "home_assistant")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "%")
  |> filter(fn: (r) => r["friendly_name"] == "Android Auto ratio" or r["friendly_name"] == "Zone basicfit ratio" or r["friendly_name"] == "Zone thuis ratio" or r["friendly_name"] == "Zone werk ratio")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["domain"] == "sensor")
  |> filter(fn: (r) => r["entity_id"] == "android_auto_ratio" or r["entity_id"] == "zone_basicfit_ratio" or r["entity_id"] == "zone_thuis_ratio" or r["entity_id"] == "zone_werk_ratio")
  |> aggregateWindow(every: 1d, fn: last, createEmpty: false)
  |> yield(name: "last")

but the result is like this, but that’s strange because some days are 100% for one sensor. which is not correct:

When I remove the every 1d , it gives me this:
But I want to display one percentages for each data stream per day.

I can’t manage to get a graph that shows it like (the same data only showed in Home Assistant):

maybe it has something to do with the aggregate function “last”. but when I use “max” or “sort” I don’t get the correct graph either.


Hello @JBoesh,
I’d suggest trying to change the visualization from graph to bar to start.
You can also click the customize button and get some more options there that might help.

I’m not sure why you’re not getting the data you expect.
Please note that aggregateWindow() aggregates data in 1d intervals using the Unix epoch (1970-01-01T00:00:00Z UTC) as the start.

You can have aggregateWindow start grouping intervals based on the start date with this:

For me to help you further I ask that you add a limi(n:20), delete the aggregatewindow function, and share the CSV output here please.