Use of variables in data links

  • Environment:
    Graphana 8.5.3
    docker-compose (using image bitnami/grafana:8.5.3)
    Client: Edge on Windows 10 pro

  • What am I trying to achieve?
    One dashboard contains a table.
    Clicking on a row should open a second dashboard.
    That latter dashboard should use a value from the selected row in its query.

  • How am I trying to achieve it?
    First dashboard uses a data link on the table.
    The data link includes the key value pair cncID=cnc2 as a URL parameter.
    e.g. http://localhost:3000/mySecondDashboard&cncID=cnc2
    The target dashboard tries to use ${cncID} in a query.

  • What happened?
    The ${cncID} doesn’t get replaced at all, resulting in an invalid query.

  • What did you expect to happen?
    I would have expected that my query on the second dashboard uses the literal value cnc2 (the value of the cncID url parameter).
    The replacement seems to work fine when I replace ${cncID} with for instance ${__from}, so I seem to be using a valid replacement location.
    In other words: am I making wrong assumptions about the usability of url parameters inside a dashboard’s implementation? Or do I need to use a specific syntax to obtain the values from url parameters?

welcome to the :grafana: forum, @qootec

this sample dashboard might be useful here. Is this similar to what you want to achieve?

https://play.grafana.org/d/27c0IFkGk/data-link-with-dashboard-variable?orgId=1

Matt,

Thanks for your suggestion. It pointed me in the right direction.

Solution: you have to prepend “var-” to the name of the variable that you want to set on the URL. In my example above:
http://localhost:3000/mySecondDashboard&var-cncID=cnc2
Then the value “cnc2” gets assigned to a variable “cncID” with which you can work.

As a user, you can’t know this… Although the sample dashboards are valuable for illustrating Grafana’s abilities, from a user point of view it feels like a very inefficient way to “learn”. I’ve spent hours trying to understand why my original approach didn’t work. The documentation doesn’t mention anything about this. Browsing through all the examples in the hope of finding a similar situation is inefficient. It would be so much more comfortable for a user to have this as part of reference documentation. Did I overlook it somewhere?

Johan

1 Like