Insert Dynamic Labels for ChartJS into Template Node

Hello,

I have a flow that I am wanting to insert data into chartJS through a template node into the UI template node to view chartjs on dashboard. I have attached the pictures in the following order:

Inject => Function Node => Template Node => UI Template Node

The issue I am having is within the data field I can reference the incoming payload with {{payload.value}} but for some reason the labels field that I reference using {{payload.label}} isn't being as an options inside the chart. My suspicion is that the payload being seen for data in the template node is seen as [210, 40, 70] but since I am using the same method for the label field its seeing [Test1, Test2, Test3] which doesn't work because I think the template node doesn't recognize those as string values. Correct me if this is a bad assumption. Could anyone help me to get this to work. This is just testing data for simplicity.

image

image

image

[
{
"id": "c93a7f1f3cab2868",
"type": "template",
"z": "97e8bc0a60037121",
"name": "",
"field": "template",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "<canvas id="myChart">\n\n",
"output": "str",
"x": 480,
"y": 140,
"wires": [
[
"1d3f757555c253a9"
]
]
},
{
"id": "1d3f757555c253a9",
"type": "ui_template",
"z": "97e8bc0a60037121",
"group": "cf47fdd7b9aa2723",
"name": "",
"order": 1,
"width": 15,
"height": 12,
"format": "",
"storeOutMessages": true,
"fwdInMessages": true,
"resendOnRefresh": true,
"templateScope": "local",
"className": "",
"x": 660,
"y": 140,
"wires": [

]
},
{
"id": "fb4d4c266c4ccbb6",
"type": "inject",
"z": "97e8bc0a60037121",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[{"value":210,"label":"Test1"},{"value":40,"label":"Test2"},{"value":70,"label":"Test3"}]",
"payloadType": "json",
"x": 110,
"y": 140,
"wires": [
[
"2c60718fee0f3464"
]
]
},
{
"id": "2c60718fee0f3464",
"type": "function",
"z": "97e8bc0a60037121",
"name": "function 28",
"func": "let data = msg.payload\nlet values = data.map(value => value.value)\nlet labels = data.map(labels => labels.label)\n\n\nreturn {payload: {"value": values, "label": labels}}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": ,
"x": 250,
"y": 140,
"wires": [
[
"c93a7f1f3cab2868"
]
]
},
{
"id": "cf47fdd7b9aa2723",
"type": "ui_group",
"name": "Group 1",
"tab": "f451efd2a90a8ef8",
"order": 1,
"disp": true,
"width": 30
},
{
"id": "f451efd2a90a8ef8",
"type": "ui_tab",
"name": "Tab 2",
"icon": "dashboard",
"order": 2
}
]

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.