Grafana 8: Bar chart not working with time base labels

I am pretty exited about the announced bar chart panel and just wanted to give it a try for my use case:

I have two time series, both already have the datapoints aligned in time: This is energy received from net or delivered to the net.
For each day i want to display the value received vs. delivered next to each other side by side, just like in the announcement of the bar chart panel (https://grafana.com/docs/grafana/latest/panels/visualizations/bar-chart/#visualizing-time-series-or-multiple-result-sets).

But finally i get the message “Bar charts requires a string field”.

This is the data produced by my queries and one applied transformation:

I understand that the timestamps should be strings for the panel to work.
So first of all it would be great if it could handle timestamps natively. (I also know that there is the Time Series panel, but it cannot display bars side by side).
Second i could imagine to transform the Time colum to a string column but i dont know how to achieve it…
Is there a solution to this?

Or is there any useful chain of transformations to achieve my goal?

(I also tried the transformation “Series to rows”, but i would end up with the column labels on x axis which is not what i want.)

1 Like

I am also confused by the documentation, in my case I also have a field which is of string type and even when I do a transformation to rename the string field to Time nothing happens.
Not sure what else to try!

You probably need to use the Reduce Transform.

But I have an issue after reduction, my fields are numeric, not string.

With Loki queries, the field always contain the Label, which is quite annoying:
image

However this lets the graph display as it’s a string.

If I use the Legend field to change this to the field name {{ BotScore }}, it removes the label from the the value, but now the field is numeric, not string, so it won’t graph.

So this won’t graph:

Any ideas?

Also ordering is bad. Should be in numeric order.

In your query try [FORMAT AS] and option [Table] instead of the default [Time Series]

Unfortuentely it doesnt help, same result.

grafik

I guess that the timestamp is the problem as it is not a string (as indicated by the message “Bar charts requires a string field”).

Are there any solutions to this?
I also have a Time Series with 2 values that I need to display as bar side by side.
It’s very annoying that this seems not possible with time.

Well I kind of got it working, with 2 transformations.
But sadly the Date/Time information is lost…

I have exactly the same problem! Two number values returned from my table along with a date/time value.
If I do a transformation for the time field to a string my labels and up being just numbers.

What is the correct way to use a datetime as time column AND for the label on the X axis?

I had to do some digging but found in one of the original PR’s for the bar chart some source data:

image

link to sheet

So it looks like the bar chart requires the first column to be a string and this is used to name the group, then the rest of the columns are the bars for that group.

I was able to get the time to show up properly by jumping through a couple hoops:

I’m using a Loki query (a Loki metric query which has the same result as a Prometheus query) and I’m forcing a large step 7d with a matching range [7d] so that I’m getting weekly summaries with multiple series returned in the result, so first I needed to flatten the multiple series and I did this with an outer join transform on the Time field because my particular query which forces the step and range gives me series with aligned timestamps.

Here’s the magic though, to get the timestamp to show up for the name of the time grouping you have to convert it to a string field:

Now if you look at the dashboard in Table View:

You can see the first column is a String and the rest are numeric values of my data (for me it’s some time tracking data I’m working on)

Unfortunately this then shows the timestamp as a unix ms timestamp, however I could work around this with an override:

And then the last bit of magic, I’m using the 8.3-beta2 which has support for rotating the x-axis label and also lets you clip the length:

2 Likes

Thanks a lot, didnt realize there is the new “convert field type” transformation. This is what was missing. Works at my side :clap:

Excited it worked for you! Thank you for posting this issue with the information you gave, your detailed write up was very helpful to me.
I’ll see if I can get this feedback to the Grafana folks to see what we can do to make it easier to work with timestamps on the X axis and improve some of the documentation around the expected data formatting for bar charts.

1 Like