How to change "what should be displayed as Legend on the graph ?"

If you enable the Legend on a specific Graph then the chosen “measurement” will be displayed per default. (Graph -> Legend -> Options -> Show)

But how I can change this, not to show the name of the measurement, instead to show the specific tag value, that is part of each SQL Metric ?

Example:

Metric A : SELECT “value” FROM “4weeks”.“BASIC_STATS” WHERE “cluster” = 'Cluster-1’
Metric B : SELECT “value” FROM “4weeks”.“BASIC_STATS” WHERE “cluster” = ‘Cluster-2’

Now I want to show as a Legend
Cluster-1 Cluster-2

and not
BASIC_STATS BASIC_STATS

Use a GROUP BY and the ALIAS BY field. The alias by field uses the following convention: $tag_yourtagname. In your case, you want to group by cluster (then you only need one query rather than two) and then $tag_cluster in the ALIAS BY field.

4 Likes

Oh Thank you very very much - that helps me greatly ! :blush:
I’m very happy about Influx and Grafana , it works great together

1 Like

Can this be extended so that the “tagname” in “$tag_tagname” is a template variable?

For example, I have a template variable $GroupBy, which is set up as Custom with the possible values Application and ClientLabel (each of which correspond to tags in the data). I’m able to use $GroupBy in the panel title, as well as the GROUP BY clause. Ideally I’d like to also use it in ALIAS BY, something like

$tag_$GroupBy

so the legend will show the value of either the Application or ClientLabel tag, depending on which is selected. As is, this doesn’t work. Is there a way to do this?

Thanks!

Use the alternative syntax for the Alias By: [[GroupBy]]

But that shows the value of GroupBy, not the value of $GroupBy tag. For example, if GroupBy = Application, I’d like the legend to show Rcv1 (the value of the Application tag), not Application.

Sorry, you’re right. Then I don’t know if is possible.

Wait a second. $tag_$tagname does work.

Have you got the case wrong or spelt your template variable wrong?

OK, I got it working. Using the non-edit mode, the query ends up being

SELECT non_negative_derivative(sum("messages_sent"), 1s) FROM "metric" WHERE "Type" = 'application' AND $timeFilter GROUP BY time($__interval), "/^$GroupBy$/" fill(null)

and with an ALIAS BY $tag_$GroupBy, I get “undefined” for each label.

However, if I switch into edit mode and use

SELECT non_negative_derivative(sum("messages_sent"), 1s) FROM "metric" WHERE "Type" = 'application' AND $timeFilter GROUP BY time($__interval), $GroupBy fill(null)

(manually changing "/^$GroupBy$/" to $GroupBy), then the labels appear correctly (e.g., the actual value of the $GroupBy tag for each series is shown).

I can set the GROUP BY field() value manually (using the construction interface) to $GroupBy (instead of /^$GroupBy$/) and it seems to stick.

Perhaps a little quirky, or I don’t fully grok something quite yet.

Thanks!

I realize this is an old question. I’m wondering though how I could do the same thing with the flux datasource (https://github.com/grafana/influxdb-flux-datasource/issues/42)?

Is this possible yet?

Thanks,
Andreas

Hello daniellee , I am using grafana url in react-native android mobile app , it is showing all details with graph but i am not able to select portion of graph on device,how i can achieve this ?