# Use data in an xml file to make a graph

**URL:** <https://discourse.nodered.org/t/use-data-in-an-xml-file-to-make-a-graph/41005>\
**Category:** Dashboard\
**Created:** [15 February 2021 08:45 UTC](https://discourse.nodered.org/t/use-data-in-an-xml-file-to-make-a-graph/41005 "2021-02-15T08:45:18Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Corentin](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@Corentin](https://discourse.nodered.org/u/Corentin)\
**Post date:** [15 February 2021 08:45 UTC](https://discourse.nodered.org/t/use-data-in-an-xml-file-to-make-a-graph/41005/1 "2021-02-15T08:45:18Z")

</div>

Hello,

I want to retrieve data in the following XML file in order to create graphs.

The data I want is the timestamp of each item as well as the value.

I have no idea how to proceed. Can anyone help me? Thank you.

**The X axis must be timestamp and Y = value.**

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ff5c57fe37ece301a3829a4de1eb10107e09093f.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:** [15 February 2021 09:06 UTC](https://discourse.nodered.org/t/use-data-in-an-xml-file-to-make-a-graph/41005/2 "2021-02-15T09:06:37Z")

</div>

Welcome to the forum.

The first thing to do is to send it through an XML node and see what you get out.

---

<div class="post-metadata">

**Author:** ![Corentin](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@Corentin](https://discourse.nodered.org/u/Corentin)\
**Post date:** [15 February 2021 09:11 UTC](https://discourse.nodered.org/t/use-data-in-an-xml-file-to-make-a-graph/41005/3 "2021-02-15T09:11:37Z")

</div>

Hello, thank you for your answer. Here is what I did and the results I get.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/e/9ed277039608dd8f3083a482824b660d4af2d194.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/caee850326caaff0fbdd637725041ad2966c5703.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:** [15 February 2021 10:02 UTC](https://discourse.nodered.org/t/use-data-in-an-xml-file-to-make-a-graph/41005/4 "2021-02-15T10:02:21Z")

</div>

What do the timestamps and values look like?

---

<div class="post-metadata">

**Author:** ![Corentin](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@Corentin](https://discourse.nodered.org/u/Corentin)\
**Post date:** [15 February 2021 10:05 UTC](https://discourse.nodered.org/t/use-data-in-an-xml-file-to-make-a-graph/41005/5 "2021-02-15T10:05:06Z")

</div>

To that :

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/8/784be92c56ecf27ac3264b39610035ccf0abfe25.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:** [15 February 2021 10:16 UTC](https://discourse.nodered.org/t/use-data-in-an-xml-file-to-make-a-graph/41005/6 "2021-02-15T10:16:23Z")

</div>

The timestamps look ok, presumably you know what time zone they are in. The values will need to be turned into numbers, presumably 1,04 represents 1.04. If the file cold be produced with dots instead of commas it would help, but it isn't a big problem.

Now that you have the data in a javascript object you just need to turn it into the format required by the chart. [This document](https://github.com/node-red/node-red-dashboard/blob/master/Charts.md) describes what is needed, in the section Stored Data.

You haven't given us any indication of your experience, if you are a node red beginner then I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Then have a look at the node red docs pages [Working with Messages](https://nodered.org/docs/user-guide/messages) and [Writing Functions](https://nodered.org/docs/user-guide/writing-functions).

Then if necessary come back and tell us which bit you are having difficulty with.

---

<div class="post-metadata">

**Author:** ![Corentin](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@Corentin](https://discourse.nodered.org/u/Corentin)\
**Post date:** [15 February 2021 13:36 UTC](https://discourse.nodered.org/t/use-data-in-an-xml-file-to-make-a-graph/41005/7 "2021-02-15T13:36:43Z")

</div>

Thank you very much for the information.

Nevertheless, I am stuck at converting string to number.

msg2.payload is of type string and I would like it to be in full so that it can be used for creating the chart.

So I tried using Number (), parseInt (), and parseFloat () but no positive results.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/1/516b666724e5f2bc974f5d252459fc8b7c49b297.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/4/f48447c4d793cb478381054504d705ae169fa996.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:** [15 February 2021 13:58 UTC](https://discourse.nodered.org/t/use-data-in-an-xml-file-to-make-a-graph/41005/8 "2021-02-15T13:58:47Z")

</div>

It is useless posting a screenshot showing only half the line length. To post code please copy/paste it and use the `</>` button at the top of the forum entry window when pasting it in.  
Do you mean you don't know how to convert data values to numbers? If so then something like

```auto
let splitValue = whatever.split(",")
blabla = Number(splitValue[0] + "." + splitValue[1]) 

```

For the date you should be able to feed it directly into `newDate(theDateString)`. The graph will accept Date objects I think in the structure. If not the use `toTime()` to convert to milliseconds.  
For converting the arrays of values and numbers look at the `Array.map()` function rather than iterating through the array.

---

<div class="post-metadata">

**Author:** ![Corentin](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@Corentin](https://discourse.nodered.org/u/Corentin)\
**Post date:** [15 February 2021 14:02 UTC](https://discourse.nodered.org/t/use-data-in-an-xml-file-to-make-a-graph/41005/9 "2021-02-15T14:02:20Z")

</div>

Please excuse me. Here is the code in question.

```auto
var msg1={};
var msg2={};

p=msg.payload;
node.log(typeof p);
msg1.payload=p.data["FTI-018"][0].timestamp[0].timestamp;
msg1.topic="Timestamp";
msg2.payload = p.data["FTI-018"][0].values[0].value;
msg2.topic = "Value";

//return msg2;
//return [msg1,msg2];
//var data = [];
//data.push({"x": p.data["FTI-018"][0].timestamp[0].timestamp, "y" : (p.data["FTI-018"][0].values[0].value)});
//msg.payload = {label: "label", data, series: "X"};
//return msg;

//msg.payload = [];
//msg.payload.push(msg1.payload);
//msg.payload.push(msg2.payload);
//return msg;

var m={};
m.labels = [msg1.payload];
m.series = ['Series 1'];
m.data = [msg2.payload];
//m.data = msg2.payload;
return {payload:[m]};

```

---

<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:** [15 February 2021 14:08 UTC](https://discourse.nodered.org/t/use-data-in-an-xml-file-to-make-a-graph/41005/10 "2021-02-15T14:08:49Z")

</div>

My previous post should help with converting the values, but you seem to have misinterpreted the information in the link I posted. For filling the chart with information from a set of data you need to construct it as described in the section Stored Data.

---

<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:** [17 March 2021 14:08 UTC](https://discourse.nodered.org/t/use-data-in-an-xml-file-to-make-a-graph/41005/11 "2021-03-17T14:08:53Z")

</div>

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