First, I'm new for Node-red . I'm trying to make this gauge respondsive in real time. I was initially able to send my data to the screen, but the gauge didn't move with the numbers.
The reason why I don't use ui-gauge is because the dashboard has some limitations. (I am an intern working on my thesis which my teacher wants to be beautiful in the dashboard design) So I opted not to use the dashboard directly that's why I have written html ,css,js instead of using tools from the dashboard directly.
P.S. i just use inject-node for example, in my thesis i will use mqtt to send data.
Here's the flow I modified code to get the msg.direct load.
[
{
"id": "8a39156f80306c37",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": "",
"env": []
},
{
"id": "b09e9aebc4f92c57",
"type": "ui_template",
"z": "8a39156f80306c37",
"group": "6cc66c72e5f6e0e7",
"name": "",
"order": 1,
"width": 7,
"height": 9,
"format": "<div class=\"gauge\">\n <div class=\"gauge__body\">\n <div class=\"gauge__fill\"></div>\n <div ng-bind-html=\"msg.payload\" class=\"gauge__cover\"></div>\n </div>\n</div>\n<style>\n .gauge {\n width: 100%;\n max-width: 250px;\n font-family: \"Roboto\", sans-serif;\n font-size: 32px;\n color: #004033;\n }\n \n .gauge__body {\n width: 100%;\n height: 0;\n padding-bottom: 50%;\n background: #b4c0be;\n position: relative;\n border-top-left-radius: 100% 200%;\n border-top-right-radius: 100% 200%;\n overflow: hidden;\n }\n \n .gauge__fill {\n position: absolute;\n top: 100%;\n left: 0;\n width: inherit;\n height: 100%;\n background: #009578;\n transform-origin: center top;\n transform: rotate(0.25turn);\n transition: transform 0.2s ease-out;\n }\n \n .gauge__cover {\n width: 75%;\n height: 150%;\n background: #ffffff;\n border-radius: 50%;\n position: absolute;\n top: 25%;\n left: 50%;\n transform: translateX(-50%);\n \n /* Text */\n display: flex;\n align-items: center;\n justify-content: center;\n padding-bottom: 25%;\n box-sizing: border-box;\n }\n</style>\n<script>\n const gaugeElement = document.querySelector(\".gauge\");\n \n function setGaugeValue(gauge, value) {\n if (value < 0 || value> 1) {\n return;\n }\n \n gauge.querySelector(\".gauge__fill\").style.transform = `rotate(${\n value / 2\n }turn)`;\n gauge.querySelector(\".gauge__cover\").textContent = `${Math.round(\n value * 100\n )}%`;\n }\n \n // Set initial value of the gauge to 0.3\n setGaugeValue(gaugeElement, 0.3);\n \n // Listen for incoming messages from Node-RED\n // and update the gauge value accordingly\n this.onmessage = function (msg) {\n if (msg.hasOwnProperty(\"payload\")) {\n setGaugeValue(gaugeElement, msg.payload);\n }\n };\n</script>",
"storeOutMessages": true,
"fwdInMessages": true,
"resendOnRefresh": true,
"templateScope": "local",
"className": "",
"x": 420,
"y": 220,
"wires": [
[]
]
},
{
"id": "7d193ecae230ff14",
"type": "inject",
"z": "8a39156f80306c37",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "23",
"payloadType": "num",
"x": 270,
"y": 220,
"wires": [
[
"b09e9aebc4f92c57"
]
]
},
{
"id": "6cc66c72e5f6e0e7",
"type": "ui_group",
"name": "Group 1",
"tab": "76ccc464c8a197e5",
"order": 1,
"disp": true,
"width": 7
},
{
"id": "76ccc464c8a197e5",
"type": "ui_tab",
"name": "Tab 17",
"icon": "dashboard",
"order": 17
}
]
And here is the original html,css,js respondsive code.
[
{
"id": "c49aea348796f5be",
"type": "tab",
"label": "Flow 7",
"disabled": false,
"info": "",
"env": []
},
{
"id": "93419fe7153549f5",
"type": "ui_template",
"z": "c49aea348796f5be",
"group": "6cc66c72e5f6e0e7",
"name": "",
"order": 1,
"width": 0,
"height": 0,
"format": "<div class=\"gauge\">\n <div class=\"gauge__body\">\n <div class=\"gauge__fill\"></div>\n <div class=\"gauge__cover\"></div>\n </div>\n</div>\n<style>\n .gauge {\n width: 100%;\n max-width: 250px;\n font-family: \"Roboto\", sans-serif;\n font-size: 32px;\n color: #004033;\n }\n \n .gauge__body {\n width: 100%;\n height: 0;\n padding-bottom: 50%;\n background: #b4c0be;\n position: relative;\n border-top-left-radius: 100% 200%;\n border-top-right-radius: 100% 200%;\n overflow: hidden;\n }\n \n .gauge__fill {\n position: absolute;\n top: 100%;\n left: 0;\n width: inherit;\n height: 100%;\n background: #009578;\n transform-origin: center top;\n transform: rotate(0.25turn);\n transition: transform 0.2s ease-out;\n }\n \n .gauge__cover {\n width: 75%;\n height: 150%;\n background: #ffffff;\n border-radius: 50%;\n position: absolute;\n top: 25%;\n left: 50%;\n transform: translateX(-50%);\n \n /* Text */\n display: flex;\n align-items: center;\n justify-content: center;\n padding-bottom: 25%;\n box-sizing: border-box;\n </style>\n\n<script>\n const gaugeElement = document.querySelector(\".gauge\");\n \n function setGaugeValue(gauge, value) {\n if (value < 0 || value> 1) {\n return;\n }\n \n gauge.querySelector(\".gauge__fill\").style.transform = `rotate(${\n value / 2\n }turn)`;\n gauge.querySelector(\".gauge__cover\").textContent = `${Math.round(\n value * 100\n )}%`;\n }\n \n setGaugeValue(gaugeElement, 0.5);\n</script>",
"storeOutMessages": true,
"fwdInMessages": true,
"resendOnRefresh": true,
"templateScope": "local",
"className": "",
"x": 480,
"y": 200,
"wires": [
[]
]
},
{
"id": "6cc66c72e5f6e0e7",
"type": "ui_group",
"name": "Group 1",
"tab": "76ccc464c8a197e5",
"order": 1,
"disp": true,
"width": 7
},
{
"id": "76ccc464c8a197e5",
"type": "ui_tab",
"name": "Tab 17",
"icon": "dashboard",
"order": 17
}
]
Thank you in advance!