# Draw TGraph with time axis

**URL:** <https://root-forum.cern.ch/t/draw-tgraph-with-time-axis/38296>\
**Category:** ROOT\
**Tags:** jsroot\
**Created:** [March 6, 2020, 2:50pm UTC](https://root-forum.cern.ch/t/draw-tgraph-with-time-axis/38296 "2020-03-06T14:50:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guilherme](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/77aa72/32.png) [@Guilherme](https://root-forum.cern.ch/u/Guilherme)\
**Post date:** [March 6, 2020, 2:50pm UTC](https://root-forum.cern.ch/t/draw-tgraph-with-time-axis/38296/1 "2020-03-06T14:50:59Z")

</div>

Hi guys,

I’ve been using JSROOT to develop my own web interface, that basically sends TH1F jsons with only one value with their timestamp. Do you know how to create a TGraph (or TMultiGraph) with time series on its axis?  
I tried with:

```auto
let time_list = [];
let value_list = [];
for (let n=0;n<all_files.length;n++) {
    let time_secs = timestamps[n];
    let the_value = all_files[n].fArray[0]
    time_list.push(time_secs);
    value_list.push(the_value );
}
let graph1 = JSROOT.CreateTGraph(all_files.length, time_list, value_list);
graph1 .fHistogram.fXaxis.fTimeDisplay = true

```

but the fHistogram appears to be null.  
Do you have any insight?

Thanks in advance!  
\_JSROOT Version:5.8.0

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [March 6, 2020, 3:08pm UTC](https://root-forum.cern.ch/t/draw-tgraph-with-time-axis/38296/2 "2020-03-06T15:08:48Z")

</div>

Hi,

`graph1.fHistogram` is empty when one just creates `TGraph`  
One should do it extra:

```auto
graph1 .fHistogram = JSROOT.CreateHistogram("TH1I", 20);

```

Here is example how custom histogram can be created for `TMultiGraph`

[https://root.cern/js/latest/api.htm#custom\_html\_tmultigraph](https://root.cern/js/latest/api.htm#custom_html_tmultigraph)  
[https://root.cern/js/latest/api.htm#custom\_html\_tmultigraph\_src](https://root.cern/js/latest/api.htm#custom_html_tmultigraph_src)

Then you need to configure `fXaxis` for timedisplay:

```auto
graph1 .fHistogram.fXaxis.fTimeDisplay = true
graph1 .fHistogram.fXaxis.fTimeFormat = "see root docu"
graph1 .fHistogram.fXaxis.fMin = time_list[0]
graph1 .fHistogram.fXaxis.fMin = time_list[time_list.length-1]
graph1 .fHistogram.fXaxis.fTitle = "axis title"

```

Hope, it works

---

<div class="post-metadata">

**Author:** ![Guilherme](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/77aa72/32.png) [@Guilherme](https://root-forum.cern.ch/u/Guilherme)\
**Post date:** [March 6, 2020, 4:43pm UTC](https://root-forum.cern.ch/t/draw-tgraph-with-time-axis/38296/3 "2020-03-06T16:43:23Z")

</div>

Amazing! It worked!  
But I had to change fMin to fXmin, and the second fMin to fXmax, otherwise the data would not appear.  
I guess I have to deal with the TimeOffset “by hand” right?

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [March 6, 2020, 4:53pm UTC](https://root-forum.cern.ch/t/draw-tgraph-with-time-axis/38296/4 "2020-03-06T16:53:48Z")

</div>

Time offset can be coded in `fTimeFormat`.  
And sorry for typo in xmin/xmax values names.

---

<div class="post-metadata">

**Author:** ![Guilherme](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/77aa72/32.png) [@Guilherme](https://root-forum.cern.ch/u/Guilherme)\
**Post date:** [March 6, 2020, 5:04pm UTC](https://root-forum.cern.ch/t/draw-tgraph-with-time-axis/38296/5 "2020-03-06T17:04:58Z")

</div>

No problem. Evertything is working now.  
I simply did:  
`graph1.fHistogram.fXaxis.fTimeFormat = "%F 1970-01-01 00:00:00"`

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [March 20, 2020, 5:16pm UTC](https://root-forum.cern.ch/t/draw-tgraph-with-time-axis/38296/6 "2020-03-20T17:16:41Z")

</div>

Closed on March 20, 2020, 5:16pm UTC

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