Derriving legend label values from a postgres query

  • What Grafana version and what operating system are you using? 10.4 managed via AWS

  • What are you trying to achieve? I have a query with a time value as x axis, metric value as y
    and each value has a label for this instance we will call it name
    i would like for each line in the graph for the legend to show the value of the “name”

  • How are you trying to achieve it?

    t AS "time", 
    weight AS "metric", 
    name AS "field"
FROM my_table;
  • What happened?
    i have tried with overrides and transforms to no avail would love a helping hand if someone can

  • What did you expect to happen?
    for the value of the legend to give me all the names of the “aliases” that are in the current graph based on the time

You need to group by, e. g.

SELECT
 t AS "time", - - some time aggregation macro should be used here
 AVG(weight) AS "value", 
 name AS "metric"
FROM my_table
-- also time condition should be used it in WHERE statement - it doesn't make sense to select all values, when only dashboard time range will be visualized
GROUP BY 3

I will take the pointers on optimizing the query
like so


but my main issue stays.
The legend should be of all the different aliases that have values in x time frame. am i missing something?
@jangaraj

Format it as a timeseries, not as a table.