Change color based on additional fields from query

I am trying to change the color of specific metrics based on additional fields selected. I am using the following page as a basis for this attempt: Transform data

The specific section is as follows:

I can get this to work for “max” as the example illustrates, but the following does not work:

SELECT
  quote_date AS "time",
  short_name AS metric,
  trigger_allocation,
  '{ "fixedColor": "green", "mode": "fixed" }' AS color
FROM symbol_price_trigger_allocation
WHERE
  $__timeFilter(quote_date)
AND parent_code = '${PortfolioCode}'
ORDER BY 1,2

This produces labels with the extra tag added to the label as illustrated below:

We are using Grafana v9.1.6

Hi @the-dude-abides ,

Thank you for your post. I would like to ask if this scenario can be replicated in https://play.grafana.org/ ? Probably under explore page or also creating a dashboard about this?

This could help us to understand the issue. Kindly also share the link here from https://play.grafana.org/ once you did it.

If not, could you also try to play around with explore option on your grafana instance and share he re the raw query provided by explore?

Something like this screenshot:

Thanks

Thanks for the fast reply. I will do as suggested. Once complete, I will post back to the community.

Cheers.

The following is a look at the two queries:
Query A:

SELECT
  s.quote_date AS "time",
  s.short_name AS metric,
  s.ron_to_high
FROM symbol_price_metrics s, symbol_allocation a, symbol_allocation_item i
WHERE
  $__timeFilter(s.quote_date)
AND a.parent_symbol = '${ParentSymbolId}'
AND a.id = i.symbol_allocation
AND i.child_symbol = s.id
ORDER BY s.quote_date, i.item_sort_order, s.short_name

Query B:

SELECT
  s.quote_date AS "time",
  s.short_name AS metric,
  '#00ff00' AS color
FROM symbol_price_metrics s, symbol_allocation a, symbol_allocation_item i
WHERE
  $__timeFilter(s.quote_date)
AND a.parent_symbol = '${ParentSymbolId}'
AND a.id = i.symbol_allocation
AND i.child_symbol = s.id
ORDER BY s.quote_date, i.item_sort_order, s.short_name

The Transformation for “Config from query results” is as follows:

And a sample of the data is as follows:

So my question is, how do you set the color of a metric in Query A from a configuration in Query B?

Thanks,
-jm

1 Like