Michael
Michael

Reputation: 443

Set width of bars in Grafana when using flux query

I have the following flux query that aggregates on a monthly basis

from(bucket: "some-bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "some-value" and r._field == "some-other-value")
  |> aggregateWindow(every: 1mo, fn: sum)

that gives the following bar chart

enter image description here

As you can see the bars are very thin. I would like them to be one month wide. Is there a way to manually set this or a different way to construct the query to get Grafana to detect this?

Thanks in advance for any help.

Upvotes: 1

Views: 1970

Answers (1)

cidermole
cidermole

Reputation: 6078

It seems that this has to do with the time spacing of the very last record. A workaround for me was to use the _start column of groups (instead of the default _stop) to restore the _time column.

Try this:

from(bucket: "some-bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "some-value" and r._field == "some-other-value")
  |> aggregateWindow(every: 1mo, fn: sum, timeSrc: "_start")

See https://stackoverflow.com/a/66107599/1616948 for details.

Upvotes: 1

Related Questions