How to draw an histogram with float values with JSROOT?

Hello,
i would like to draw an histogram TH1 with jsroot. From the examples i found, i wrote this simple script:
https://www-fourier.ujf-grenoble.fr/~faure/enseignement/javascript/code/ex_JSROOT_TH1D.html
a sample of the code is:
for (var ix = 0; ix < 20; ix++) {
var bin = h1.getBin(ix + 1), val = 5*ix/20.;
h1.setBinContent(bin, val);
}
The problem is that the y values are integers instead of float numbers:
ex_TH1

I don’t know how to correct this?
By the way, is it possible to change the title? to put some x-title? to remove the stat-box?
more generally how to perform operations similar to what is explained in the c++ documentation here:
https://root.cern.ch/doc/v608/classTH1.html
Thanks a lot,
best regards,
Frédéric.

Hi,

In your code you are using function:

var h1 = JSROOT.CreateTH1(20, 20);

You should use:

h1 = JSROOT.CreateHistogram("TH1F", 20);

Regards,
Sergey

Hi,

Just add some minimal docu: http://jsroot.gsi.de/dev/jsdoc/JSROOT.html#.CreateHistogram

Regards,
Sergey

Hi Sergey,
thanks, it works well.

In this same example is there a way to write in javascript:

h1.SetTitle(‘y = f(x)’);
h1.SetXTitle(‘x’);
h1.SetYTitle(‘y’);
h1.SetStats(0);

in a similar syntax as we do in c++ according to:
https://root.cern.ch/doc/v608/classTH1.html

Regards,
Frédéric.

Hi Frédéric,

No. Only very few methods from c++ are implemented in JavaScript.

One should write:

h1.fTitle = ‘y = f(x)’;
h1.fXaxis.fTitle = "x";
h1.fYaxis.fTitle = "y";
h1.InvertBit(JSROOT.TH1StatusBits.kNoStats);

Regards,
Sergey

Hi Sergey,
thanks very much.
I also found that

h1.fXaxis.fXmin = -1.; 
h1.fXaxis.fXmax = 1.; 

works fine in order to specify the X interval values.

But i don’t found how to fix the interval in Y, i.e. what is the equivalent of the c++ functions TH1:SetMaximum() and TH1:SetMinimum() ?
Is there a way to discover all the available functions in some source file by myself?

Regards,
Frédéric.

 h1.fMinimum = 0;
 h1.fMaximum = 1000;

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