# Node-red-dashboard Chart rewrite epoch time X axis labels

**URL:** https://discourse.nodered.org/t/node-red-dashboard-chart-rewrite-epoch-time-x-axis-labels/29174
**Category:** Dashboard
**Created:** [29 June 2020 14:51 UTC](https://discourse.nodered.org/t/node-red-dashboard-chart-rewrite-epoch-time-x-axis-labels/29174 "2020-06-29T14:51:53Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![johnwalicki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnwalicki/32/8848_2.png) [@johnwalicki](https://discourse.nodered.org/u/johnwalicki)
#### Post date: [29 June 2020 14:51 UTC](https://discourse.nodered.org/t/node-red-dashboard-chart-rewrite-epoch-time-x-axis-labels/29174/1 "2020-06-29T14:51:53Z")

</div>

Dave CJ - There are several Weather Company APIs that return historical data that I would like to plot in charts. I build the chart data series with Epoch time as the X axis. It looks fine but the X axis labels are somewhat meaningless. I was wondering if there is a way to set the labels to a date format. Something like 06-23-2020 06-24-2020 06-25-2020  
-- John

Two examples:

 ![Selection_043](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/1629dd251a32bbf02c2ae41b79ae832616c6cb7a.png) ![Selection_042](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/16e90e919d75b69ca5dc9a682360bdd97b3b925b.png)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [29 June 2020 15:07 UTC](https://discourse.nodered.org/t/node-red-dashboard-chart-rewrite-epoch-time-x-axis-labels/29174/2 "2020-06-29T15:07:56Z")

</div>

The timestamps should be in javascript milliseconds.  
I looks like they are wrong. Show us some of the data that you are sending to the chart and tell us what the timestamps represent.

---

<div class="post-metadata">

### Author: ![johnwalicki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnwalicki/32/8848_2.png) [@johnwalicki](https://discourse.nodered.org/u/johnwalicki)
#### Post date: [29 June 2020 15:18 UTC](https://discourse.nodered.org/t/node-red-dashboard-chart-rewrite-epoch-time-x-axis-labels/29174/3 "2020-06-29T15:18:56Z")

</div>

The timestamps are in seconds 1593342000 (one timestamp per day)  
The chart is correct but the x-axis autoselects meaningless tick marks.  
Here's a function that builds a chart of 30 days of temperature data (the data is looking backwards in time so I reverse it for the chart)

```auto
var MonthlyHistoryTempChart = [{
    "series":["Daily Temp Max", "Daily Temp Min"],
    "data":[[],[]],
    "labels":["Daily Max Temp", "Daily Min Temp"]
}];

for( var i=(msg.payload.validTimeUtc.length)-1; i >= 0 ; i--) {
    MonthlyHistoryTempChart[0].data[0].push( {"x":msg.payload.validTimeUtc[i],"y":msg.payload.temperatureMax[i] } ) ;
    MonthlyHistoryTempChart[0].data[1].push( {"x":msg.payload.validTimeUtc[i],"y":msg.payload.temperatureMin[i] } ) ;
}

msg.payload = MonthlyHistoryTempChart;
return msg;

```

---

<div class="post-metadata">

### Author: ![johnwalicki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnwalicki/32/8848_2.png) [@johnwalicki](https://discourse.nodered.org/u/johnwalicki)
#### Post date: [29 June 2020 15:53 UTC](https://discourse.nodered.org/t/node-red-dashboard-chart-rewrite-epoch-time-x-axis-labels/29174/4 "2020-06-29T15:53:07Z")

</div>

Essentially, I want to set the underlying chart.js options to label the x-axis as days.

From the chart.js docs I see:  
[https://www.chartjs.org/docs/latest/axes/cartesian/time.html#time-units](https://www.chartjs.org/docs/latest/axes/cartesian/time.html#time-units)  
which tells me to set the options object. How can I pass this through the node-red-dashboard chart node to the underlying chart.js?

```auto
var chart = new Chart(ctx, {
    type: 'line',
    data: data,
    options: {
        scales: {
            xAxes: [{
                type: 'time',
                time: {
                    unit: 'day'
                }
            }]
        }
    }
});

```

---

<div class="post-metadata">

### Author: ![johnwalicki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnwalicki/32/8848_2.png) [@johnwalicki](https://discourse.nodered.org/u/johnwalicki)
#### Post date: [29 June 2020 16:11 UTC](https://discourse.nodered.org/t/node-red-dashboard-chart-rewrite-epoch-time-x-axis-labels/29174/5 "2020-06-29T16:11:07Z")

</div>

Searching through this forum, I see some chart.js examples which use the ui\_template node. I was hopeful that I wouldn't need to go down that path for a common time series use case.

---

<div class="post-metadata">

### Author: ![johnwalicki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnwalicki/32/8848_2.png) [@johnwalicki](https://discourse.nodered.org/u/johnwalicki)
#### Post date: [29 June 2020 16:21 UTC](https://discourse.nodered.org/t/node-red-dashboard-chart-rewrite-epoch-time-x-axis-labels/29174/6 "2020-06-29T16:21:25Z")

</div>

gah - I'm going to crawl under my rock again. Dave is brilliant and has already provided this capability. Not certain when it became an option in the Chart node.

 ![Selection_044](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/de470e258ea04cd17ad6f36c6dde5606090d4d8b.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: [29 July 2020 16:21 UTC](https://discourse.nodered.org/t/node-red-dashboard-chart-rewrite-epoch-time-x-axis-labels/29174/7 "2020-07-29T16:21:26Z")

</div>

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