Reputation: 103
So I am new to Grafana, I have a table and a bar chart:
The bar chart query is as follows:
select coalesce(group_name) as group_name,
sum(sales) filter (where device_type = 'HEAD_PHONES') as HEAD_PHONES,
sum(sales) filter (where device_type = 'GUITAR') as guitar,
sum(sales) filter (where device_type = 'XBOX') as xbox,
sum(sales) filter (where device_type is null ) as other
from test
where area = 'AREA1' <--make this grafana variable
group by coalesce(group_name);
I would like if every time the user clicks a row within the table, the bar chart is updated using the same query but the area changed depending on the row clicked. How do I make it a Grafana variable supposing there are more than a 100 areas?
Here is db:
Upvotes: 0
Views: 19818
Reputation: 98
In grafana there is "variables", go to "dashboard settings" --> variables, from there create new variable with type "query", name it like "area" and put sql query(select area from test), save it, and then in your select query: select ... where area in ($area).
Upvotes: 2