Draw TGraph with time axis

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:

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

Hi,

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

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_src

Then you need to configure fXaxis for timedisplay:

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

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?

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

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

Thanks a lot!

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