Context Parameters
context.dataβ
Data from data sources. The display of one or multiple data rows from the selected data frame or from all data frames is determined by the Render template option. It can be one of three values: Every Row, All Rows, and All data.
Usageβ
context.data;
Exampleβ
const data = context.data;
context.elementβ
Current HTML element.
Usageβ
context.element;
Exampleβ
const element = context.element;
context.dataFrameβ
Selected Data Frame for Every Row, All Rows templates.
Usageβ
context.dataFrame;
Exampleβ
const frame = context.dataFrame;
Panelβ
panel.handlebarsβ
Handlebars library.
Usageβ
context.handlebars;
Exampleβ
context.handlebars.registerHelper("unique", (context, key) => {
return [...new Set(context.map((item) => item[key]))];
});
panel.panelDataβ
Panel data.
Usageβ
context.panelData;
Exampleβ
const dashboardTimeZone = context.panelData.timeZone;
const dashboardTimeRange = context.panelData.timeRange;
context.handlebars.registerHelper("tz", () => dashboardTimeZone);
context.handlebars.registerHelper("range", () => dashboardTimeRange);
context.handlebars.registerHelper(
"browser",
() => Intl.DateTimeFormat().resolvedOptions().timeZone
);
Grafanaβ
grafana.eventBusβ
Publish and subscribe to application events.
Usageβ
context.grafana.eventBus;
Exampleβ
const subscriber = eventBus.getStream(RefreshEvent).subscribe(() => {
// to do
});
grafana.getLocale()β
Returns the user's locale: 'en', 'fr', 'es', and so on.
Usageβ
context.grafana.getLocale();
Exampleβ
const messages = {
Hello: {
en: "Hello",
fr: "Salut",
es: "Hola",
},
Default: {
en: "The query didn't return any results.",
fr: "La requΓͺte n'a renvoyΓ© aucun rΓ©sultat.",
es: "La consulta no arrojΓ³ ningΓΊn resultado.",
},
};
const locale = getLocale();
context.handlebars.registerHelper(
"translate",
(message) => messages[message][locale] ?? messages[message]["en"]
);
grafana.locationServiceβ
The locationService
works with the browser location and history.
Usageβ
context.grafana.locationService;
Exampleβ
context.grafana.locationService.reload();
const history = context.grafana.locationService.history;
grafana.replaceVariables()β
The replaceVariables()
function to interpolate variables.
Usageβ
context.grafana.replaceVariables();
Exampleβ
const bonjour = context.grafana.replaceVariables("${variable}");
console.log(bonjour.toUpperCase());
grafana.timeRangeβ
Time range of the current dashboard.
Usageβ
context.grafana.timeRange;
Exampleβ
const timeRange = context.grafana.timeRange;
console.log(timeRange);
grafana.timeZoneβ
Time zone of the current dashboard.
Usageβ
context.grafana.timeZone;
Exampleβ
const timeZone = context.grafana.timeZone;
console.log(timeZone);
grafana.notifyError([header, message])β
Displays an error notification.
Usageβ
context.grafana.notifyError([header, message]);
Exampleβ
context.grafana.notifyError(["Error Title", `Show error message`]);
Argumentsβ
header
string. Error titlemessage
string. Error message
grafana.notifySuccess([header, message])β
Displays a success notification.
Usageβ
context.grafana.notifySuccess([header, message]);
Exampleβ
context.grafana.notifySuccess(["Success Title", `Success message`]);
Argumentsβ
header
string. Success titlemessage
string. Success message
grafana.themeβ
Contains grafana Theme object.
Usageβ
context.grafana.theme;
Exampleβ
const theme = context.grafana.theme;
console.log(theme);
grafana.refresh()β
Function to refresh dashboard panels using application events.
Added in: v5.7.0
Usageβ
context.grafana.refresh();