# Change format of values from array from integer to unix-timestamp for a chart

**URL:** https://discourse.nodered.org/t/change-format-of-values-from-array-from-integer-to-unix-timestamp-for-a-chart/81863
**Category:** General
**Created:** [8 October 2023 19:00 UTC](https://discourse.nodered.org/t/change-format-of-values-from-array-from-integer-to-unix-timestamp-for-a-chart/81863 "2023-10-08T19:00:10Z")
**Posts on this page:** 1
**Showing post:** 4

<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: [9 October 2023 18:16 UTC](https://discourse.nodered.org/t/change-format-of-values-from-array-from-integer-to-unix-timestamp-for-a-chart/81863/4 "2023-10-09T18:16:25Z")

</div>

Your issue is you are not using a time series data in the chart, so you will need to format your labels array values.  
try

```auto
 times[i] = `${dt.getHours()}:${dt.getMinutes()}`;

```

 ![chrome_screenshot_1696875419043](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7d25d11e4371f2ba66151fe7e6891f5b65163162.png)

[edit] to pad the hours and minutes try

```auto
    times[i] = `${dt.getHours().toString().padStart(2, "0")}:${dt.getMinutes().toString().padStart(2, "0")}`;

```

output the is  
`07:05`

Or return time series data, Example.

```auto
[{"id":"d3b95a9fa28b88da","type":"inject","z":"bf569dbfc3bc07ed","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"TIME\":1696831539163,\"MINUTESUM\":0},{\"TIME\":1696831601046,\"MINUTESUM\":2.58},{\"TIME\":1696831659189,\"MINUTESUM\":2.6},{\"TIME\":1696831719379,\"MINUTESUM\":2.6},{\"TIME\":1696831781108,\"MINUTESUM\":2.83},{\"TIME\":1696831839203,\"MINUTESUM\":3.36},{\"TIME\":1696831899218,\"MINUTESUM\":3.57},{\"TIME\":1696831959105,\"MINUTESUM\":4.26},{\"TIME\":1696832021111,\"MINUTESUM\":4.42},{\"TIME\":1696832079160,\"MINUTESUM\":4.58},{\"TIME\":1696832139102,\"MINUTESUM\":4.8},{\"TIME\":1696832199151,\"MINUTESUM\":4.94},{\"TIME\":1696832259215,\"MINUTESUM\":5.18},{\"TIME\":1696832319103,\"MINUTESUM\":5.82},{\"TIME\":1696832379210,\"MINUTESUM\":6.27},{\"TIME\":1696832439201,\"MINUTESUM\":6.5},{\"TIME\":1696832499225,\"MINUTESUM\":7.26},{\"TIME\":1696832559245,\"MINUTESUM\":6.95},{\"TIME\":1696832619184,\"MINUTESUM\":7.14},{\"TIME\":1696832679394,\"MINUTESUM\":7.83},{\"TIME\":1696832739283,\"MINUTESUM\":7.77},{\"TIME\":1696832799188,\"MINUTESUM\":8.82},{\"TIME\":1696832859187,\"MINUTESUM\":10.42},{\"TIME\":1696832919285,\"MINUTESUM\":9.93},{\"TIME\":1696832979228,\"MINUTESUM\":9.63},{\"TIME\":1696833039114,\"MINUTESUM\":10.76},{\"TIME\":1696833099187,\"MINUTESUM\":9.56},{\"TIME\":1696833159178,\"MINUTESUM\":10.1},{\"TIME\":1696833219310,\"MINUTESUM\":9.69}]","payloadType":"json","x":90,"y":380,"wires":[["04917addcc6292d8"]]},{"id":"04917addcc6292d8","type":"function","z":"bf569dbfc3bc07ed","name":"function 64","func":"const data = [];\n\n\nmsg.payload.forEach(function(value) {\n data.push({\n y: value.MINUTESUM,\n x: value.TIME\n })\n});\n\n\n\nmsg.payload = [{\n series: [\"MINUTe SUM\"],\n data: [data],\n}];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":230,"y":380,"wires":[["f291eb649626f7bb"]]},{"id":"f291eb649626f7bb","type":"ui_chart","z":"bf569dbfc3bc07ed","name":"","group":"8b5cde76.edd58","order":8,"width":0,"height":0,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":450,"y":380,"wires":[["43b43dd4375a2790"]]},{"id":"43b43dd4375a2790","type":"debug","z":"bf569dbfc3bc07ed","name":"debug 344","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":380,"wires":[]},{"id":"8b5cde76.edd58","type":"ui_group","name":"default","tab":"8f03e639.85956","order":1,"disp":false,"width":"12","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

```

Also If this is data return from a data base you could have the data base return the data using AS syntax, e.g.

```auto
SELECT MINUTESUM AS y, TIME AS x
FROM table_name ......

```

Then you would not need the function to foreEach through the data, as it will be return in the correct format to simply add to the chart data object property.

---

_[View the full topic](https://discourse.nodered.org/t/change-format-of-values-from-array-from-integer-to-unix-timestamp-for-a-chart/81863)._
