JSROOT and JSON data

Dear ROOT experts,

Here below my issue:

-) I am using JSROOT.CreateHistogram (e.g. h1) to create nice TH1F and TH2F histograms embedded in an webpage.
-) Data are filled in the histograms (h1.Fill(), or h1.SetBinContent()) and drawn by using method JSROOT.redraw()

This part works just fine.

-) I would like to retrieve the json data related to my charts, in order to be able to open them locally.
-) I am using var json = JSROOT.toJSON(h1). Data exported indeed make sense (TH1_original.txt)
-) Unfortunately C++ macros cannot load it:
Error in TRint::HandleTermInput(): std::domain_error caught: type must be number, but is string
-) I changed by hands few parameters (TH1_fixed.txt) -> fNcells and fNbins were associated to a string value.
-) TH1_fixed.txt works on C side.

On the 2D side things are less easy.
-) I did manage to create TH2s and draw them.
-) The JSON data (TH2_original.txt) retrieved seem “healthy” after the correction above (TH2_fixed.txt), but when I run my C script the plot is empty, despite not getting any error.

On the c side I am using the following code:

TH2F* histo = nullptr;
TString data = json_data_as_string
TBufferJSON::FromJSON(histo, data);

To use JSROOT I am using:

Can you provide me some more insight about this issue I am experiencing? Am I doing something wrong?

Many thanks in advance,

Edoardo Farina

TH2_fixed.txt (3.1 KB) TH2_original.txt (3.1 KB)

TH1_fixed.txt (2.5 KB)
TH1_original.txt (2.6 KB)

Hi Edoardo,

Up to now it was never checked if JSON histogram data, created in JSROOT, can be used in ROOT itself. Typically it is other way around - ROOT provides JSON data which can be visualized with JSROOT.

I will check if problem can be fixed.


Hi Edoardo,

Seems to be you are using string parameter as number of bins in the JSROOT.CreateHistogram call. Therefore you have fNbins:"20" and fNcells:"202" (last should be 22). Try to provide integer parameter - may be it solves your problem.

Try also with TH2. If it does not work - please send me your updated JSON data.


Thanks a lot Sergey for looking into this so quickly.

Indeed, as you noticed, I was not “casting” bin number correctly.
TH1 histograms now works.

I am attaching the TH2 case; in this case, again, I don’t see any entry in the plot.
Actually, strange to me, data seem to be there, since if zoom-in the stat box is updated!!
And even more strange, if I change the visualisation to 3D I see them (see attachment)!
Probably I am still missing how to properly read it back.

I am also attaching a simple macro to show what I am doing to read it…

Thanks again!

draw.C (3.2 KB) TH2_fixed_v2.txt (3.1 KB)


I found two problems.
First - JSROOT does not fill statistic and not configure entries. You should do it by hand before drawing:


Second - Z axis configuration is wrong. In JSON code for fZaxis following members should be changed:


For the moment you can try to modify JSON “by hand”.
I will try to provide a fix in JSROOT next week.


Thanks a lot Sergey.

Indeed it works according to your suggestions.
I was however wondering whether the entries number could be provided by JSROOT in the json data directly.
Related to this point, I also saw that even after setting the number of entries I can’t, for example, fit the data (Warning in : Fit data is empty).
I am not an expert, I know the usage of JSROOT I am doing it is not the usual and I don’t want to waste your time.

Thanks again,

Yes, this is my plan

Hi Edoardo,

I add several commits to dev version of JSROOT.
Now it should set correct member values and increment entries counter when histo.Fill() method is called.
Can you try https://root.cern/js/dev/ version of JSROOT?
If it will work for you, I will create 5.8.1 release with these changes.


Dear Sergey,

Thank you again for looking into this so quickly.
Indeed, it works perfectly! I also managed to fit locally my plots after having generated and downloaded them from the browser.

Many thanks again!
Best regards,


Now correspondent fixes in latest JSROOT release 5.8.1.
You again can use https://root.cern/js/latest/ version.

Thanks for reporting a problem.


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