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,
histo.fYaxis.fLabels=yLabels;
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:
EDIT:
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,
Emil