Bar Gauge : How to show Series name from a query's row value (MySQL)?

I’ve got this query :

SELECT hostmacro.value as macro, count(hostmacro.value) as compte FROM zabbix.hostmacro group by hostmacro.value;

I want to use the first column’s row values of the query (macro) as the series’s names for my Bar Gauge and use the 2nd column values (compte) as the value for each series. Right now, i’m not getting the expected result :

If i switch to a table view, i can see the 2 columns like this :
image

Anyone knows how to do this or if it’s possible with the new panel?

Thanks!

type $__cell_0 in the Field title template

4 Likes

Ah yes, it works now. I was a bit confused with the tooltip, as i tought i had to enter $__cell_{0}

image

Thanks!

Hello! I cannot see that field in my query builder, could you please be so kind to post the full working query so I can edit my own? Thank you!

Same problem here. I am not using the query builder. “Field title template” - where??

Hello,
What must I add to my query to show series? Is it…

SELECT * , $__series.name{Bar1}, FROM table WHERE No=10

or

SELECT * , $__field.name{Bar1}, FROM table WHERE No=10

or what? Thkns…

Hi, here an exemple of query:

SELECT distinct(hostname) as hostname,count() as total FROM DB.Table
group by hostname order by count(
) desc

In the ‘Display’ tab on ‘Title’ field put : $__cell_0

It will make you bar title as the first field of your SQL query and the lenght of the bar will be the count(*)

Hi, i am trying to change the series name in a query very similar to this, but i cannot.
My query is like this:

SELECT sum(weight) FROM gitlab_issues where $timeFilter group by project

It works fine, but on the series title in the bar gauge it displays “gitlab_issues.sum {project: HR}”, when I would like it to show only the tag values, in this case “HR”, or at least removing the “gitlab_issues.sum” part.

Thanks.

Have you tried SELECT sum(weight) as HR FROM… ?

Antony.

Hi Torkel,

The other options as of _series_name and _field_name don’t appear to work. Am I missing something?

Thanks

Could you share other configuration settings? I run very similar query with two columns returned, but for some reason gauge indicator shows each colum/row combination as separate gauge.

I have set “Title” field to $__cell_0

If I display same query as table, it shows 5 rows as expected:

Thanks!



this is my query
select
sum(if(dik.ID = ‘1’ , dik.value, 0)) as ‘_a1’,
sum(if(dik.ID = ‘2’ , dik.value, 0)) as ‘_a2’,
sum(if(dik.ID = ‘3’ , dik.value, 0)) as ‘_a3’,
sum(if(dik.ID = ‘4’ , dik.value, 0)) as ‘_a4’,
sum(if(dik.ID = ‘5’ , dik.value, 0)) as ‘_a5’,
sum(if(dik.ID = ‘6’ , dik.value, 0)) as ‘_a6’,
sum(if(dik.ID = ‘7’ , dik.value, 0)) as ‘_a7’

from
(SELECT
__timeGroup(Start,'5m',0) as "time", sum(VehicleActivities) as value, ID FROM request_info WHERE __timeFilter(Start)
GROUP BY ID
ORDER BY Start) as dik

I get same to all bars in bar gauge.
Somebody can help

Using this macros could help us on the group by month?

Please share your query after changed it as suggested.

Worked for me – this is what I was doing wrong.

I had trouble with the solution Torkel provided because (1) there did not seem to be any “Title” field for the bar gauge visualization and (2) I was mispelling the variable.

(1) In my version of Grafana, I had to modify the “Display Name” in the Field tab.

(2) I was only using one underscore. So, instead of “dollar underscore underscore cell underscore zero” ( $__cell_0 ), I was inputting “dollar underscore cell underscore zero” ( $_cell_0 )

The following is before and after. Instead of the metric “Count” appearing underneath each bar, the group by value appears (in this case, the “service.keyword”):

1 Like

I’m using v7.0.6 and struggling with Bar Gauge.

My query is super simple.
SELECT mode,count(job) FROM info WHERE $__timeFilter("time") GROUP BY mode

This gives the expected plot but all items are named count. Then, I try to modify using the Display name option under Field, but using any name causes the plot to show “No Data”. If I call it “Count”, the plot says “m is undefined”. I’m at a loss here on how to get this working.

Edit:
I created a new panel and things seem to be working now. Another post suggests using ${__series.name} for Grafana v7+ but that didn’t work for me. I’m using ${__cell_0} and it works.