在Grafana中使用变量来隐藏或显示列。

huangapple go评论73阅读模式
英文:

hide or show columns in grafana with a variable

问题

I am creating this table, however, I am trying to hide/show columns based on a variable (the user can select which columns they see).

我正在创建这个表格,但是我试图根据一个变量来隐藏/显示列(用户可以选择看到哪些列)。

I came up with the following code:

我想出了以下的代码:

select
Rank() over (Partition BY score
ORDER BY Speler) ranking,
Speler, $column, Rank as '# pred', Naam as 'Team pred', position as '#', score from fact_score_sheet_act
where Speler in ($Names)
ORDER BY Speler, Competitie, RANK ASC

$column is a variable containing the column names.
It only shows the name as a value, instead of values from the database.

$column是一个包含列名的变量。
它只显示名称作为值,而不是来自数据库的值。

What am I doing wrong?

我做错了什么?

英文:

so i am creating this table, however i am trying to hide / show columns based on a variable (user can select which columns she/he sees).

I came with the following code:

select 
Rank() over (Partition BY  score
ORDER BY Speler) ranking,
Speler, $column, Rank as '# pred', Naam as 'Team pred', position as '#', score from fact_score_sheet_act
where Speler in ($Names)
ORDER BY Speler, Competitie, RANK ASC

$column is a variable containing the column names
it only shows the name as value, instead of values from the database,

What am i doing wrong?

答案1

得分: 2

你的变量被替换为带引号的逗号分隔列表。因此,MySQL 将其解释为字符串列表,并将它们作为这样返回。

关于这个问题的文档说:
>对于 MySql 数据源,默认行为是将多个值作为带引号的逗号分隔字符串连接起来:'server01','server02'。在某些情况下,您可能希望获得一个不带引号的逗号分隔字符串:server01,server02。您可以使用下面列出的高级变量格式选项来实现这一点。

在您的查询中使用${column:csv}

英文:

Your variable is substituted with quoted comma-separated list. As a result MySql interprets it as a list of strings, and returns them as such.

Documentation on this matter says:
>[T]he default for the MySql data source is to join multiple values as comma-separated with quotes: 'server01','server02'. In some cases, you might want to have a comma-separated string without quotes: server01,server02. You can make that happen with advanced variable formatting options listed below.

Use ${column:csv} in your query instead.

huangapple
  • 本文由 发表于 2023年6月29日 05:40:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76576879.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定