-) 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);
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.
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…
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.
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.
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.