-
Hi all! I am trying to make certain parts of an SVG file to "hide" when a certain value turns up from the data base but i cant get it to work. This might seem fairly simple but im new to javascript and i find this plugin to be quite tricky to understand for a beginner. Thankfull for all the help i cant get. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello @Flipparen. I've made a repo that hides the SVG element when the value is 1. Datasource used https://grafana.com/grafana/plugins/marcusolsson-static-datasource/ Here's a simplified version: HTML/SVG <svg viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect id="orange-rectangle" x="69" y="162" width="181" height="175" fill="#f80"/>
<rect id="blue-rectangle" x="250" y="162" width="181" height="175" fill="#08f"/>
</svg> onRender const getMetricByName = (alias) => {
const filteredAliasSeries = data.series.filter((series) => series.name == alias);
if (filteredAliasSeries.length > 0) {
return filteredAliasSeries[0].fields[1].state.calcs.last;
}
return 'No data';
};
htmlNode.getElementById('orange-rectangle').style.display = getMetricByName('orange-metric') ? "none" : "inline"; I highly recommend to use the repo example |
Beta Was this translation helpful? Give feedback.
Hello @Flipparen.
I've made a repo that hides the SVG element when the value is 1.
Datasource used https://grafana.com/grafana/plugins/marcusolsson-static-datasource/
Here's a simplified version:
HTML/SVG
onRender