# Displaying data from Inject Node as a Pie Chart

**URL:** https://discourse.nodered.org/t/displaying-data-from-inject-node-as-a-pie-chart/94817
**Category:** Dashboard
**Tags:** dashboard-2
**Created:** [22 January 2025 09:02 UTC](https://discourse.nodered.org/t/displaying-data-from-inject-node-as-a-pie-chart/94817 "2025-01-22T09:02:34Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![joehi](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@joehi](https://discourse.nodered.org/u/joehi)
#### Post date: [22 January 2025 09:02 UTC](https://discourse.nodered.org/t/displaying-data-from-inject-node-as-a-pie-chart/94817/1 "2025-01-22T09:02:34Z")

</div>

Hello, I am new to using Raspberry Pi and Node-RED. Currently, I am facing a confusing issue about how to display data from the inject node to the template node so that it can appear as a pie chart on the UI/dashboard. I am using Node-RED Dashboard version 2.0. Can anyone help me?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/67e0ed113f910cf6b984b53310667217075fbf59.png)

```auto
[
    {
        "id": "980622ebca896d23",
        "type": "ui-template",
        "z": "982297f0c4d67695",
        "group": "5e9cd1bf9f97ea78",
        "page": "",
        "ui": "",
        "name": "Pie Chart Vue.js",
        "order": 5,
        "width": "5",
        "height": "3",
        "format": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Pie Chart Example</title>\n <script src=\"https://cdn.jsdelivr.net/npm/chart.js\"></script>\n <style>\n body {\n font-family: Arial, sans-serif;\n text-align: center;\n padding: 20px;\n }\n\n .container {\n position: relative;\n display: flex;\n align-items: center;\n padding: 20px;\n border: 2px solid white;\n border-radius: 10px;\n background-color: rgba(0, 0, 0, 0.5);\n }\n\n .leds-container {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n margin-left: 20px;\n }\n\n .send {\n position: absolute;\n top: 10px;\n left: 10px;\n padding: 10px 20px;\n background-color: #007bff;\n color: white;\n border: none;\n border-radius: 5px;\n cursor: pointer;\n text-decoration: none;\n }\n\n .send:hover {\n background-color: #0056b3;\n }\n\n canvas {\n width: 150px !important;\n height: 150px !important;\n }\n\n .led-container {\n display: flex;\n flex-direction: row;\n align-items: center;\n margin-bottom: 10px;\n }\n\n .led {\n width: 15px;\n height: 15px;\n border-radius: 50%;\n margin-right: 10px;\n }\n\n .led-red {\n background-color: red;\n }\n\n .led-green {\n background-color: green;\n }\n\n .led-text {\n font-size: 16px;\n color: white;\n }\n </style>\n</head>\n<body>\n <div class=\"container\">\n <button class=\"send\" onclick=\"sendDashboard()\">Home</button>\n <canvas id=\"myPieChart\"></canvas>\n <div class=\"leds-container\">\n <div class=\"led-container\">\n <div class=\"led led-red\"></div>\n <span class=\"led-text\">Not Running</span>\n </div>\n <div class=\"led-container\">\n <div class=\"led led-green\"></div>\n <span class=\"led-text\">Running</span>\n </div>\n </div>\n </div>\n <script>\n function sendDashboard() {\n console.log('Navigating to Dashboard...');\n }\n\n const data = {\n labels: ['Not Running', 'Running'],\n datasets: [{\n label: 'Status',\n data: [30, 70], // Example data (percentage)\n backgroundColor: ['rgba(255, 99, 132, 0.7)', 'rgba(54, 162, 235, 0.7)'],\n borderColor: ['rgba(255, 99, 132, 1)', 'rgba(54, 162, 235, 1)'],\n borderWidth: 1\n }]\n };\n\n const config = {\n type: 'pie',\n data: data,\n options: {\n responsive: true,\n plugins: {\n legend: { display: false },\n title: { display: false }\n }\n }\n };\n\n const ctx = document.getElementById('myPieChart').getContext('2d');\n const chart = new Chart(ctx, config);\n </script>\n</body>\n</html>\n",
        "storeOutMessages": true,
        "passthru": false,
        "templateScope": "local",
        "className": "",
        "x": 440,
        "y": 1040,
        "wires": [
            [
                "7aafba82adab52cd"
            ]
        ]
    },
    {
        "id": "70c02b8d0732ef6a",
        "type": "inject",
        "z": "982297f0c4d67695",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "Running",
        "payload": "58",
        "payloadType": "num",
        "x": 230,
        "y": 1020,
        "wires": [
            [
                "980622ebca896d23"
            ]
        ]
    },
    {
        "id": "7aafba82adab52cd",
        "type": "debug",
        "z": "982297f0c4d67695",
        "name": "debug 12",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 620,
        "y": 1040,
        "wires": []
    },
    {
        "id": "3c3b847ba187e471",
        "type": "inject",
        "z": "982297f0c4d67695",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "Running",
        "payload": "98",
        "payloadType": "num",
        "x": 230,
        "y": 1060,
        "wires": [
            [
                "980622ebca896d23"
            ]
        ]
    },
    {
        "id": "5e9cd1bf9f97ea78",
        "type": "ui-group",
        "name": "led",
        "page": "d0621b8f20aee671",
        "width": "12",
        "height": "11",
        "order": 2,
        "showTitle": false,
        "className": "",
        "visible": "true",
        "disabled": "false",
        "groupType": "default"
    },
    {
        "id": "d0621b8f20aee671",
        "type": "ui-page",
        "name": "Charts Example",
        "ui": "57cca3cf771b1acc",
        "path": "/charts-example",
        "icon": "chart-box-outline",
        "layout": "flex",
        "theme": "5075a7d8e4947586",
        "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": 1,
        "className": "",
        "visible": "true",
        "disabled": "false"
    },
    {
        "id": "57cca3cf771b1acc",
        "type": "ui-base",
        "name": "dashboard",
        "path": "/dashboard",
        "appIcon": "",
        "includeClientData": true,
        "acceptsClientConfig": [
            "ui-notification",
            "ui-control"
        ],
        "showPathInSidebar": false,
        "headerContent": "none",
        "navigationStyle": "none",
        "titleBarStyle": "fixed",
        "showReconnectNotification": false,
        "notificationDisplayTime": "5",
        "showDisconnectNotification": false
    },
    {
        "id": "5075a7d8e4947586",
        "type": "ui-theme",
        "name": "persentase running/not running",
        "colors": {
            "surface": "#ffffff",
            "primary": "#ffffff",
            "bgPage": "#ffffff",
            "groupBg": "#ffffff",
            "groupOutline": "#ffffff"
        },
        "sizes": {
            "pagePadding": "12px",
            "groupGap": "12px",
            "groupBorderRadius": "4px",
            "widgetGap": "12px",
            "density": "default"
        }
    }
]

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [22 January 2025 10:16 UTC](https://discourse.nodered.org/t/displaying-data-from-inject-node-as-a-pie-chart/94817/2 "2025-01-22T10:16:03Z")

</div>

Hi, welcome to the forum.

Some pointers to help you get your question to the right folk.

1. There are 2 main node packages named node-red-dashboard. the old (now depreciated) `node-red-dashboard` and the newer, VUE based `@flowfuse/node-red-dashboard` (also referred to as **dashboard 2** ). Your tag states #node-red-dashboard which by itself is interpreted as dashboard 1 (legacy). I would recommend you set this to #dashboard-2 (you can update the tags after posting)

2. Unfortunately, your flow will be unusable. In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

---

<div class="post-metadata">

### Author: ![joepavitt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joepavitt/32/59722_2.png) [@joepavitt](https://discourse.nodered.org/u/joepavitt)
#### Post date: [24 January 2025 11:23 UTC](https://discourse.nodered.org/t/displaying-data-from-inject-node-as-a-pie-chart/94817/3 "2025-01-24T11:23:22Z")

</div>

Hi @joehi - there is a Pie Chart already available in the "Chart" node - [docs](https://dashboard.flowfuse.com/nodes/widgets/ui-chart.html#pie-doughnut-charts) - I'd recommend taking a look at that, rather than trying to roll out your own in a Template node.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [24 January 2025 11:44 UTC](https://discourse.nodered.org/t/displaying-data-from-inject-node-as-a-pie-chart/94817/4 "2025-01-24T11:44:32Z")

</div>

> [@joepavitt](#):
>
> Pie Chart already available in the "Chart" node - [docs](https://dashboard.flowfuse.com/nodes/widgets/ui-chart.html#pie-doughnut-charts)

And in the Link joe provided there is a button labelled "Try Demo" at the top of the page that has downloadable demo flows

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/7/975380ada6af202c70be85f920e922432472fd72.png)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [23 February 2025 11:44 UTC](https://discourse.nodered.org/t/displaying-data-from-inject-node-as-a-pie-chart/94817/5 "2025-02-23T11:44:44Z")

</div>

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