Bar char based on SQL with 2 items in GROUP BY

My bar chart is based on Postgres SQL:

select the_date, name, max(value) as max_value
from T
where the_date >= DATE(‘2023-08-01T07:00:00Z’) and the_date <= DATE(‘2023-09-01T06:59:59Z’)
group by the_date, name
order by the_date, name

In Bar chart properties I specified X Axis as “the_date”
In Postgres table the “the_date” column has type “DATE”.

Problem #1: currently the bar chart shows the x-axis labels as several identical values

17:00:00.000 17:00:00.000 17:00:00.000 17:00:00.000 17:00:00.000

But I want to show on X-axis the dates in format MM-DD, for example
08-01 08-02 08-03

Problem #2:
All bars for the same date should be under the single X-axis label.
But currently every bar has his own X-axis label.

Welcome @mlubinsky

What data do you see when running the same query in pgadmin?

select the_date, 
   name, 
max(value) as max_value
from T
where the_date >= DATE('2023-08-01T07:00:00Z') 
and the_date <= DATE('2023-09-01T06:59:59Z')
group by the_date, name
order by the_date, name

For SQL above I see records like this in PG Admin

2023-08-02 name_1 20.0
2023-08-02 name_2 25.0
2023-08-02 name_3 14.0
2023-08-04 name_1 18.0
2023-08-04 name_2 12.0
2023-08-04 name_3 15.0

Exactly the same records I see in Grafana Table, it means Grafana got the right dataset. :slight_smile:

1 Like

So it results in this, so grafana is doing it correctly?

The X-axis labels on image in post above is different from mine.
I got labels like this instead of YYYY-MM-DD:
17:00:00.000 17:00:00.000 17:00:00.000 17:00:00.000
( this is problem #1 in my original post).

The problem #2 in my original post is present on image in post above:
every data point has individual X-label date even it belong to the same date.
I need to show values for the same date under the single X-axis date label (using different colors for different names).
I need something like left bar chart here:

I know how to assign the individual colors to names, but I do not know how combine them under the single common date.

1 Like

Or stacked

This is almost what I want,
But there is one problem:
On screenshot above I see the legend like this:
value name_1
value name_2
value name_3

Question: how to remove the prefix “value” to show only

name_1
name_2
name_3
?
Thank you a lot!

I am having a problem in understanding the screenshot above.
I understand only that the 2nd transformation is applied:
“Grouping to matrix”.
On screenshot above I see under “Grouping to matrix”:
Column: metric

In my case I have the drop down list
value name_1
value name_2
value name_3

But it is not clear for me to how to remove the prefix “value”.

I want to clarify that the names list and the number of items in the names list is not fixed:
name_1
name_2
name_3

name_N

Hence the solution for removing prefix should not
ask user to
apply transformation for every individual name_N by clicking on every individual name

Do you have a better solution?

I found this workaround: assign the empty alias column name in SQL:

select the_date,
name,
max(value) as " "
from T
where the_date >= DATE(‘2023-08-01T07:00:00Z’)
and the_date <= DATE(‘2023-09-01T06:59:59Z’)
group by the_date, name
order by the_date, name

1 Like