Template variables
Use template variables to create dynamic, reusable dashboards that let you change query parameters without editing individual panels. For general information about template variables, refer to Templates and variables (opens in new tab).
Before you begin
- Configure the Finnhub data source.
- Understand Grafana template variables (opens in new tab).
- Know how to write queries in the Finnhub query editor.
Supported variable types
The Finnhub data source supports the following variable types:
| Variable type | Supported |
|---|---|
| Query | Yes |
| Custom | Yes |
| Data source | Yes |
| Ad hoc filters | No |
Use variables in queries
Variables work in the Symbol, Search, Exchange and Category fields, written as $variable or ${variable}.
- The plugin replaces each of those fields with one string, so use single-value variables.
- The plugin uppercases Symbol after it replaces the variable.
- Resolution, Metric and Free Query Text don't interpolate variables.
For example, add a text box variable named symbol with the value AAPL, then set Symbol in a panel to $symbol. The panel queries the symbol the variable holds.
Annotation queries interpolate the same four fields as panel queries do.
Query variables
A query variable fills its drop-down by running a query against Finnhub, so its options stay current with your data. Use one to let viewers pick a value, such as a ticker, and update every panel that uses it.
To create a query variable:
- Navigate to Dashboard settings > Variables.
- Click Add variable.
- Select Query as the variable type.
- Select the Finnhub data source.
- Choose a Data type.
- Fill the fields the type shows, such as Symbol or Search.
The variable editor is the same query editor as a panel uses, with the same fields and the same data types.
The first string field of the query result becomes both the option value and the option text. Add a Symbol lookup or Peers query to list tickers, because both types return a string field.
For example, to list the peers of a company:
- Add a text box variable named
searchwith a company name as its value. - Add a query variable named
company, set Data type to Symbol lookup and set Search to$search. The options are the matching tickers. - Add a query variable named
peer, set Data type to Peers and set Symbol to$company. The options are the peer tickers. - Use
$peerin the Symbol field of a panel query.
Grafana stores the peer variable query as this target:
{
"refId": "PeerVar",
"type": "peers",
"symbol": "$company",
"search": "",
"resolution": "1",
"metric": "price",
"exchange": "US",
"category": "general"
}
Trades opens a stream and returns no response body to shape, so you can't use it as a variable source.