# Unable to show labels on bar chart

**URL:** <https://discourse.nodered.org/t/unable-to-show-labels-on-bar-chart/84933>\
**Category:** General\
**Created:** [26 January 2024 07:36 UTC](https://discourse.nodered.org/t/unable-to-show-labels-on-bar-chart/84933 "2024-01-26T07:36:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [26 January 2024 07:36 UTC](https://discourse.nodered.org/t/unable-to-show-labels-on-bar-chart/84933/1 "2024-01-26T07:36:12Z")

</div>

With this function I read data from a txt file. Because there may be more lines of data for the same month, the function will use the last one for each month.

```auto
// Function to process load shedding data
const processLastEntryPerMonth = (lines) => {
    let monthlyData = {};
    lines.forEach(line => {
        let parts = line.split(': ');
        if (parts.length === 2) {
            let date = new Date(parts[0]);
            let month = date.toLocaleString('en-US', { month: 'long' });
            let timeParts = parts[1].split(':');
            let hours = parseInt(timeParts[0]) + parseInt(timeParts[1]) / 60;
            monthlyData[month] = hours; // Store the last value for each month
        }
    });
    return monthlyData;
};

// Assuming msg.payload is the raw data from your file
const lines = msg.payload.split('\n').filter(line => line.trim() !== '');
let monthlyData = processLastEntryPerMonth(lines);

// Format data for the chart
let m = {
    series: [""],
    data: [],
    labels: []
};

for (let month in monthlyData) {
    m.labels.push(month); // Month names as labels
    m.data.push(Math.round(monthlyData[month])); // Load shedding hours for each month
}

return { payload: [m], topic: msg.topic };

```

My problem is that I am unable to show the labels (Month name) for each bar.  
This is my actual result

 ![Screenshot 2024-01-26 at 09.31.34](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/3/939c8ad3fea553e69834f51a59d250007089b446.png)

What am I doing wrong? Why the labels (January, February) are not showing under the relevant bars?  
Thanks for helping

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 January 2024 08:52 UTC](https://discourse.nodered.org/t/unable-to-show-labels-on-bar-chart/84933/2 "2024-01-26T08:52:53Z")

</div>

> [@FeliceM](#):
>
> ` m.data.push(Math.round(monthlyData[month]));`

Try

```auto
 m.data[0].push(Math.round(monthlyData[month]));

```

As data should be a array of array/s.  
And

```auto
let m = {
    series: [""],
    data: [[]],
    labels: []
};

```

---

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [26 January 2024 11:02 UTC](https://discourse.nodered.org/t/unable-to-show-labels-on-bar-chart/84933/3 "2024-01-26T11:02:21Z")

</div>

Thank you. That did it!

---

<div class="post-metadata">

**Author:** ![jwj001](https://avatars.discourse-cdn.com/v4/letter/j/8e8cbc/32.png) [@jwj001](https://discourse.nodered.org/u/jwj001)\
**Post date:** [8 February 2024 18:13 UTC](https://discourse.nodered.org/t/unable-to-show-labels-on-bar-chart/84933/4 "2024-02-08T18:13:54Z")

</div>

Hi, what version of node-red Dashboard are you using? I and using Dashboard v2 and also having problems finding the right way to build my data.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [8 February 2024 18:30 UTC](https://discourse.nodered.org/t/unable-to-show-labels-on-bar-chart/84933/5 "2024-02-08T18:30:44Z")

</div>

If you have an issue with the dashborad 2 ui-chart please start a topic with your question, include incoming data and describe in full your expected output, and issues you are gaving.  
More Info of chart in dashboard 2 here [Chart ui-chart | Node-RED Dashboard 2.0](https://dashboard.flowfuse.com/nodes/widgets/ui-chart.html#bar-graph)

---

<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:** [22 February 2024 18:31 UTC](https://discourse.nodered.org/t/unable-to-show-labels-on-bar-chart/84933/6 "2024-02-22T18:31:17Z")

</div>

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