Setting Legend text from MySQL query

I’m using Grafana to display some information stored in a MySQL database on a time_series graph.

If this is an example of the type of query I’m using how do I change the legend labels.

SELECT
$__time(date),
field,
int1 as metric_int1,
int2 as metric_int2,
int3 as metric_int3
FROM mytable
WHERE field = ‘mycrit’
ORDER BY date asc

The legend labels come out as:
“metric_int1 mycrit” “metric_int2 mycrit” “metric_int3 mycrit”

But I would like them to be:
“int1” “int2” “int3”

Is there a way to do this ?

Hello @steveglw, you can switch over to the “Transform” tab (next to the Query tab) and choose the “Orginanize fields” transformation which presents all fields which you can reorder or rename or even hide. There are also other options like the “Rename by regex” transformation.

2nd option would be to use Overrides in the edit panel on the right for each of your desired fields (in this case all 3 of them) and then use “Standard options > Display name” to change each field name to “int1”, and so on.

The benefit of the 2nd option is that you can stack multiple override properties on a single field if you want to give it a unique look among all other fields.

2nd Option was perfect. Thank very much.

1 Like