The magic settings to make a bar graph in Grafana

February 26, 2020

Suppose, not hypothetically, that you want to make a Grafana panel that shows a bar chart (or graph), because bar charts are a great way to show a summary of something instead of getting lost in the details of a standard graph over time. Grafana fully supports this, but exactly how you do it is sufficiently non-obvious that I've now forgotten and had to re-discover it at least twice now. So now I'm writing it down so I can find it again.

(This is sort of covered in the documentation, but you have to know where to look and part of it isn't clear.)

Bar charts aka bar graphs are a form of graph, so they fall under the 'graph' panel type. Although current versions of Grafana have a bar gauge panel type, you probably don't want to use it for this and it's certainly currently not the normal approach. To create a bar graph, you want three settings together:

  • In the 'Query' tab, set the duration of each of your queries to 'instant' and leave the format for each of your queries as the default of 'time series'.

  • In the 'Visualization' tab, set the draw mode to 'bars' instead of anything else, then the crucial magic step is to set the X-axis mode to 'series' instead of the default of 'time'. Since we're doing an instant query, the X-axis 'value' can be left at 'total' or changed to 'current' to be clearer.

    (I believe that if you did a non-instant query, the various options for 'value' here would determine what value the bars showed for each separate series.)

If you set the query to be instant but change nothing else, you get an empty or almost entirely empty graph (with the actual values maybe visible on the far right, since 'instant' is also 'right now'). If you also switch the draw mode to 'bars', you get your single bar value for each series smeared across the entire graph, which looks rather confusing.

I was going to gripe about Grafana not deducing that you want a bar graph when you set an instant query, but there are enough moving parts here that it's not that simple. Even with an instant query you could perhaps do a histogram X-axis instead of a bar graph, for example. I wish Grafana at least put up a warning to the effect that this combination doesn't make any sense and you want to change the X-axis mode.

PS: If you set the X-axis mode to series but don't change the draw mode to 'bars', you get dots (or points) at the top of what would be each bar. This might be what you want but probably not. You can set multiple draw modes, which will give you things like bars with points at the top.

Written on 26 February 2020.
« The browsers are probably running the TLS show now
Some alert inhibition rules we use in Prometheus Alertmanager »

Page tools: View Source, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Wed Feb 26 23:08:29 2020
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.