Access to the value of a custom variable key:value from another custom variable value

Hi folks,

I have started building an interface using Grafana 10.4.1 and I’m looking everywhere to solve the problem in the topic, but I have not found any solution. I have read many posts about it and they all refer to using chained variables with query variable. I just want to use custom variables.

The result I want to achieve can be of two types:

The first one could be get the value of a custom variable setting the key from another one.

Ex:
$variable1 contains (var1 : 0, var2 : 1)
$variable2 contains (0 : 101, 1 : 200)

Result = $variable2[variable1]:value.

In alternative i can put more than one value inside a custom variable like for example

Ex:
$variable1 contains (var1 : { 0, 101}, var2 : { 1, 200})

and access to this values in some ways.

How can i achieve one of these two solutions ?

This solution does not entirely solve my problem, because I need to keep as a key an explanatory label to be displayed in the menu, while the other pair of data would correspond to an ID and a value to be associated with it.

image

Am I wrong or this solution show both menus for variable 1 and variable 2?

I need to have something like this, a dropdown menu where i can select the element using the label and then i get the id and the relative value from another variable, but is not possible to associate 2 variables. I mean probably i need to use the chained variable but I could not find any examples using them with custom variables.

Screenshot 2024-03-28 094137

I generally need to use the CARS_PAIRS value and text but i need to select the cars from the CARS variable that rappresents the dropdown menu for the user.

really ugly workaround:

1st variable: list of cars, and “models” in csv ( i used inline, but you can use a url, and get a dynamic list)

2nd variable: json array of “models” and “prices”, then filtering by getting value from the 1st selected variable

result: one drop down showing cars to select, “price” returned from json array

This is not very elegant, and can probably be simplified, but it works, and it took a surprisingly long time to do such a “simple” task…

1 Like