【发布时间】:2020-04-06 20:36:11
【问题描述】:
注意:根据@hardillb 的回答,我修复了上述流程并在下方发布了正确的流程。 提前感谢您的帮助。我是 HTML 的初学者,必须在 Node-RED 中使用它。 我有一个简单的流程(如上图链接所示)。我在有效负载中注入带有示例折线图点的消息。我想在模板节点的 HTML 脚本中接收消息,然后将接收到的 msg.payload 数据呈现在浏览器的折线图上。如果我从脚本内部生成随机图形,HTML 脚本可以正常工作,但我无法让脚本接收 msg.payload。我尝试了类似于How to send msg.payload from function node to template node
波形 HTML 中的 HTML 脚本如下。我指出了我尝试过但没有工作的 TODO。
<!DOCTYPE HTML>
<html>
<head>
<script>
window.onload = function () {
//define line graph options for CanvasJS line graph
var options = {
exportEnabled: true,
animationEnabled: true,
animationDuration: 200,
theme: "light2",
title :{
text: "Simple Line Chart"
},
axisY: {
includeZero: false
},
data: [{
type: "spline",
indexLabelFontSize: 16,
dataPoints: [] //this will be loaded with "y" values from msg.payload
}]
};
//TODO not working ---------------------
//load WaveData from msg.payload
var WaveData = [];
var createWaveData = function () {
WaveData = {{{payload}}}; //TODO fix, not working
//WaveData = [1, 2, 3, 4, 5, 4, 3, 2, 1]; //debug code, works fine, sample data is plotted on graph
}
//--------------------------------------
var updateChart = function (cnt) {
createWaveData();
options.data[0].dataPoints = [];
for (var j = 0; j < cnt; j++) {
yVal = WaveData[j];
options.data[0].dataPoints.push({y: yVal});
}
(new CanvasJS.Chart("chartContainer", options)).render();
};
var updateInterval = 2000;
setInterval(function(){ updateChart(WaveData.length) }, updateInterval);
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 370px; width:100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</body>
</html>
这是每个@hardillb 答案的正确流程。
【问题讨论】:
-
不,注入节点在这里仍然没有用处,将其完全删除。还要编辑问题以显示功能节点中的内容