在面板插件中插入变量
变量是值的占位符,您可以使用它们创建模板化查询、仪表盘或面板链接。有关变量的更多信息,请参阅模板和变量。
Grafana 提供了帮助函数用于在字符串模板中插入变量。replaceVariables
函数在 PanelProps
中可用。
将 replaceVariables
添加到参数列表中,并将用户定义的模板字符串传递给它
export function SimplePanel({ options, data, width, height, replaceVariables }: Props) {
const query = replaceVariables('Now displaying $service');
return <div>{query}</div>;
}