Hello!
I want to ask for help regarding my pie chart that is blank where nothing was displayed but the widget, I am trying to display live data from plc of how many time the machine alarm occurs. This is my first time using pie chart, any advice would be appreciated.
[
{
"id": "a802c2913f2f5b11",
"type": "debug",
"z": "4e40fbd2a88aea91",
"name": "debug 3",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 900,
"y": 420,
"wires": []
},
{
"id": "0a5c46c80121f2c1",
"type": "inject",
"z": "4e40fbd2a88aea91",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "05 19 * * *",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 130,
"y": 500,
"wires": [
[
"190902706af2c205"
]
]
},
{
"id": "190902706af2c205",
"type": "function",
"z": "4e40fbd2a88aea91",
"name": "Prepare SQL Query for Alarm Occurrences",
"func": "const now = new Date();\nconst year = now.getFullYear();\nconst month = now.getMonth();\nconst day = now.getDate();\n\nconst sevenAM = new Date(year, month, day, 7, 0, 0, 0);\nconst sevenPM = new Date(year, month, day, 19, 0, 0, 0);\n\nconst startTimeSQL = sevenAM.toISOString().slice(0, 19).replace('T', ' ');\nconst endTimeSQL = sevenPM.toISOString().slice(0, 19).replace('T', ' ');\n\nmsg.payload = `\n SELECT AlarmName, COUNT(*) as Occurrences\n FROM dbo.Alarms\n WHERE TimeDate >= '${startTimeSQL}' AND TimeDate < '${endTimeSQL}'\n GROUP BY AlarmName\n ORDER BY Occurrences DESC\n`;\n\nnode.log(\"SQL Query for Alarm Occurrences: \" + msg.payload);\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 390,
"y": 500,
"wires": [
[
"0af751af012c1567"
]
]
},
{
"id": "0af751af012c1567",
"type": "MSSQL",
"z": "4e40fbd2a88aea91",
"mssqlCN": "60c5e3d85f4c16dc",
"name": "Alarm Type",
"outField": "payload",
"returnType": 0,
"throwErrors": 1,
"query": "",
"modeOpt": "queryMode",
"modeOptType": "query",
"queryOpt": "payload",
"queryOptType": "editor",
"paramsOpt": "queryParams",
"paramsOptType": "none",
"rows": "rows",
"rowsType": "msg",
"parseMustache": true,
"params": [],
"x": 710,
"y": 500,
"wires": [
[
"a802c2913f2f5b11",
"510c4ff379ebf122"
]
]
},
{
"id": "ae02da5a5b556d2a",
"type": "ui-chart",
"z": "4e40fbd2a88aea91",
"group": "744e43174aca1731",
"name": "Alarm Occurance",
"label": "",
"order": 1,
"chartType": "pie",
"category": "",
"categoryType": "none",
"xAxisLabel": "",
"xAxisProperty": "payload.labels",
"xAxisPropertyType": "msg",
"xAxisType": "radial",
"xAxisFormat": "",
"xAxisFormatType": "auto",
"xmin": "",
"xmax": "",
"yAxisLabel": "",
"yAxisProperty": "payload.data",
"yAxisPropertyType": "msg",
"ymin": "",
"ymax": "",
"bins": 10,
"action": "replace",
"stackSeries": false,
"pointShape": "circle",
"pointRadius": 4,
"showLegend": true,
"removeOlder": 1,
"removeOlderUnit": "3600",
"removeOlderPoints": "",
"colors": [
"#0095ff",
"#ff0000",
"#ff7f0e",
"#2ca02c",
"#a347e1",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5"
],
"textColor": [
"#666666"
],
"textColorDefault": true,
"gridColor": [
"#ffffff"
],
"gridColorDefault": true,
"width": "6",
"height": "4",
"className": "",
"interpolation": "linear",
"x": 1310,
"y": 500,
"wires": [
[]
]
},
{
"id": "f5fe3c676621b6ed",
"type": "debug",
"z": "4e40fbd2a88aea91",
"name": "debug 9",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1280,
"y": 420,
"wires": []
},
{
"id": "510c4ff379ebf122",
"type": "function",
"z": "4e40fbd2a88aea91",
"name": "Format Data for Pie Chart",
"func": "const databaseResults = msg.payload;\nconst labels = [];\nconst data = [];\n\nif (Array.isArray(databaseResults)) {\n databaseResults.forEach(row => {\n labels.push(row.AlarmName);\n data.push(row.Occurrences);\n });\n}\n\nmsg.payload = {\n \"labels\": labels,\n \"data\": [data],\n \"series\": [\"Occurrences\"]\n};\n\nmsg.topic = \"Alarm Occurrences (7 AM - 7 PM)\";\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1010,
"y": 500,
"wires": [
[
"ae02da5a5b556d2a",
"f5fe3c676621b6ed"
]
]
},
{
"id": "60c5e3d85f4c16dc",
"type": "MSSQL-CN",
"tdsVersion": "7_4",
"name": "HMI",
"server": "10.183.191.9",
"port": "1433",
"encyption": true,
"trustServerCertificate": true,
"database": "HMI",
"useUTC": true,
"connectTimeout": "15000",
"requestTimeout": "15000",
"cancelTimeout": "5000",
"pool": "5",
"parseJSON": false,
"enableArithAbort": true,
"readOnlyIntent": false
},
{
"id": "744e43174aca1731",
"type": "ui-group",
"name": "Top Alarm Occurances",
"page": "36d8747804871232",
"width": "6",
"height": 1,
"order": 11,
"showTitle": true,
"className": "",
"visible": "true",
"disabled": "false",
"groupType": "default"
},
{
"id": "36d8747804871232",
"type": "ui-page",
"name": "Delta SA 03",
"ui": "e37b297fa64e1312",
"path": "/page1",
"icon": "home",
"layout": "grid",
"theme": "8796486dd6098e1f",
"breakpoints": [
{
"name": "Default",
"px": "0",
"cols": "3"
},
{
"name": "Tablet",
"px": "576",
"cols": "6"
},
{
"name": "Small Desktop",
"px": "768",
"cols": "9"
},
{
"name": "Desktop",
"px": "1024",
"cols": "12"
}
],
"order": 4,
"className": "",
"visible": true,
"disabled": false
},
{
"id": "e37b297fa64e1312",
"type": "ui-base",
"name": "My Dashboard",
"path": "/dashboard",
"appIcon": "",
"includeClientData": true,
"acceptsClientConfig": [
"ui-notification",
"ui-control"
],
"showPathInSidebar": false,
"headerContent": "page",
"navigationStyle": "default",
"titleBarStyle": "default",
"showReconnectNotification": true,
"notificationDisplayTime": 1,
"showDisconnectNotification": true,
"allowInstall": true
},
{
"id": "8796486dd6098e1f",
"type": "ui-theme",
"name": "Theme 2",
"colors": {
"surface": "#0f0f0f",
"primary": "#050505",
"bgPage": "#767474",
"groupBg": "#000000",
"groupOutline": "#ffffff"
},
"sizes": {
"density": "default",
"pagePadding": "12px",
"groupGap": "12px",
"groupBorderRadius": "4px",
"widgetGap": "1px"
}
}
]
Debug node 9
{"_msgid":"c511ed33546ce043","payload":{"labels":["Spindle 8 Low Roll","Spindle 8 Low Roll Warning","Light Curtain Violation","Spindle 2 Low Roll Warning","Spindle 1 Low Roll Warning","Spindle 1 Low Roll","Spindle 2 Low Roll","IP1 Vison Continuous Rejects","Spindle 7 Web Break","IP2 Vison Continuous Rejects","Axis 8 and 9 Guarding not Closed","IP1 Nip Missing Registration Marks","Press Start or Jog to Move Roll Lift","Spindle 1 Lift Not In Position","Island Placement Spindle 1 Web Break","Spindle 3 Web Break","Splice Clamp 1 On Alarm","IP3 Nip Missing Registration Marks","IP3 Vison Continuous Rejects"],"data":[[26,26,23,20,20,16,10,8,6,4,4,2,2,2,2,2,2,1,1]],"series":["Occurrences"]},"topic":"Alarm Occurrences (7 AM - 7 PM)","query":"\n SELECT AlarmName, COUNT(*) as Occurrences\n FROM dbo.Alarms\n WHERE TimeDate >= '2025-05-14 23:00:00' AND TimeDate < '2025-05-15 11:00:00'\n GROUP BY AlarmName\n ORDER BY Occurrences DESC\n","queryMode":"query","queryParams":[],"sqlInfo":[]}
Debug node 3
{"_msgid":"3dda5befd3b58f0f","payload":[{"AlarmName":"Spindle 8 Low Roll","Occurrences":26},{"AlarmName":"Spindle 8 Low Roll Warning","Occurrences":26},{"AlarmName":"Light Curtain Violation","Occurrences":24},{"AlarmName":"Spindle 1 Low Roll Warning","Occurrences":20},{"AlarmName":"Spindle 2 Low Roll Warning","Occurrences":20},{"AlarmName":"Spindle 1 Low Roll","Occurrences":16},{"AlarmName":"Spindle 2 Low Roll","Occurrences":10},{"AlarmName":"IP1 Vison Continuous Rejects","Occurrences":8},{"AlarmName":"Spindle 7 Web Break","Occurrences":6},{"AlarmName":"IP2 Vison Continuous Rejects","Occurrences":4},{"AlarmName":"Axis 8 and 9 Guarding not Closed","Occurrences":4},{"AlarmName":"IP1 Nip Missing Registration Marks","Occurrences":2},{"AlarmName":"Press Start or Jog to Move Roll Lift","Occurrences":2},{"AlarmName":"Spindle 1 Lift Not In Position","Occurrences":2},{"AlarmName":"IP3 Nip Missing Registration Marks","Occurrences":2},{"AlarmName":"IP3 Vison Continuous Rejects","Occurrences":2},{"AlarmName":"Island Placement Spindle 1 Web Break","Occurrences":2},{"AlarmName":"Splice Clamp 1 On Alarm","Occurrences":2},{"AlarmName":"Spindle 3 Web Break","Occurrences":2}],"topic":"","query":"\n SELECT AlarmName, COUNT(*) as Occurrences\n FROM dbo.Alarms\n WHERE TimeDate >= '2025-05-14 23:00:00' AND TimeDate < '2025-05-15 11:00:00'\n GROUP BY AlarmName\n ORDER BY Occurrences DESC\n","queryMode":"query","queryParams":[],"sqlInfo":[]}