I am trying to generate a simple plotly chart from node red using template node. Plotly correctly plots if x and y are static values, but as I use payload to get data into the plot variables it does not print. I have checked and the data is correctly transferred. Please see the code. \
Code in Mustache node
The below code works and creates a chart correctly.
<head>
<!-- Plotly.js -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<div id="myDiv"><!-- Plotly chart will be drawn inside this DIV --></div>
<script>
var trace1 = {
x:[1,2,3],//[{{payload.Temperature}}],
y:[1,2,3],//[{{payload.Temperature}}],
//mode: 'lines',
connectgaps: true
};
var data = [trace1];
var layout = {
title: 'Connect the Gaps Between Data',
showlegend: true
};
Plotly.newPlot('myDiv', data, layout, {showSendToCloud: true});
</script>
</body>
The below code doesn't work and instead plotly shows just coordinates.
<head>
<!-- Plotly.js -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<div id="myDiv"><!-- Plotly chart will be drawn inside this DIV --></div>
<script>
var trace1 = {
x:[{{payload.time}}],
y:[{{payload.Temperature}}],
mode: 'lines',
connectgaps: true
};
var data = [trace1];
var layout = {
title: 'Connect the Gaps Between Data',
showlegend: true
};
Plotly.newPlot('myDiv', data, layout, {showSendToCloud: true});
</script>
</body>
NOTE: data as viewed in the debug window is ans follows
`
x:[Tue Oct 08 2019 12:47:58 GMT-0400 (Eastern Daylight Time),Tue Oct 08 2019 12:47:28 GMT-0400 (Eastern Daylight Time),Tue Oct 08 2019 12:47:21 GMT-0400 (Eastern Daylight Time),Tue Oct 08 2019 12:46:30 GMT-0400 (Eastern Daylight Time),Tue Oct 08 2019 12:42:58 GMT-0400 (Eastern Daylight Time),Tue Oct 08 2019 12:41:17 GMT-0400 (Eastern Daylight Time),Tue Oct 08 2019 12:37:58 GMT-0400 (Eastern Daylight Time),Tue Oct 08 2019 12:37:28 GMT-0400 (Eastern Daylight Time),Tue Oct 08 2019 12:37:23 GMT-0400 (Eastern Daylight Time),Tue Oct 08 2019 12:36:17 GMT-0400 (Eastern Daylight Time)],
y:[26.76,27.76,27.51,27.11,26.76,27.15,26.75,27.9,27.77,27.23],
`
what am I doing wrong, thank you.
JavaScript new Date()
new Date() creates a new date object with the current date and time:
Sun Sep 08 2019 08:09:00 GMT-0400 (Eastern Daylight Time) Same result. What is avalid date object and how to I convert the strip to it? thanks – Ali Oct 09 '19 at 17:36