JSRoot set bin labels

Dear root people,

I am trying to create a histogram with JSRoot, on which I can set custom bin labels.

I guess I need to set the fLabels array with an array of strings,


but it doesn’t work, it gives an error, on console:

TypeError: Cannot read properties of undefined (reading 'length')
    at TAxisPainter.formatLabels (TAxisPainter.mjs:540:41)
    at TAxisPainter.produceTicksPath (TAxisPainter.mjs:854:55)
    at TAxisPainter.drawAxis (TAxisPainter.mjs:1145:26)
    at TFramePainter.drawAxes (TFramePainter.mjs:2060:34)

fLabels is an array, whose length needs to be equal to fNbins (I guess)
so this should be fine, but its not:

looking inside hist2d/TMultiGraphPainter.mjs,
I see something that may be the method I should be using:

xaxis.fLabels = create(clTHashList);
            for (let i = 0; i < graphs.arr.length; i++) {
               let lbl = create(clTObjString);
               lbl.fString = graphs.arr[i].fTitle || `gr${i}`;
               lbl.fUniqueID = graphs.arr.length - i; // graphs drawn in reverse order
               xaxis.fLabels.Add(lbl, '');

EDIT2: indeed the above worked. I would hope there is an easier way (e.g. the object could include a function to setLabels).

thanks for any guidance,

@linev can help I am sure.

1 Like


Grate that you find a solution!

Working example is this one:


Code which creates custom labels are here:

JSROOT is not intended to re-implement all ROOT methods in JavaScript.
Such custom data can be created in plain ROOT and then stored in binary or json file.


1 Like

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