Using Dygraphs in node red ui_template

44 views Asked by At

I want to use Dygraph in the node red dashboard. I used dashboard template and placed the simplest example of dygraphs in the template.

<html>
<head>
<script type="text/javascript" src="dygraph.js"></script>
<link rel="stylesheet" type="text/css" src="dygraph.css" />
</head><body>
<div id="graphdiv"></div>
<script type="text/javascript">
Dygraph.onDOMready(function onDOMready() {
g = new Dygraph(
// containing div
document.getElementById("graphdiv"),
"Date,Temperature\n" +
"2008-05-07,75\n" +
"2008-05-08,70\n" +
"2008-05-09,80\n"
);
});
</script>
</body>
</html>

with the above code the dashboard shows the graph. but if I change the data to {{msg.payload}} the dashboard does not show anything.

enter image description here

I looked in the node help and it menthoend to use

<html>
<head>
<script type="text/javascript" src="https://dygraphs.com/2.2.1/dist/dygraph.js"></script>
<link rel="stylesheet" type="text/css" src="https://dygraphs.com/2.2.1/dist/dygraph.css" />
</head>
<body>
<div id="graphdiv2" style="width:500px; height:300px;"></div>
<script type="text/javascript">
Dygraph.onDOMready(function onDOMready() {
g2 = new Dygraph(
document.getElementById("graphdiv2"),
{{msg.payload}}
);
});
</script>
</body>
</html>

Would you please help me how can I use the msg.payload in the template as input data for the dygraph?

0

There are 0 answers