GetMainPainter(divid) in JSROOT v5.9->v6


I am a beginner in javascript and with jsroot. Half a year ago I did some coding with jsroot v5.9. But now that new version is out I am having some troubles with the basics.

The problem:
In 5.9 version I used the following code to get a histogram from a plot: var obj = JSROOT.GetMainPainter(divid).draw_object.
But in the new version 6.0 this was changed and I can’t make it work.

I tried using this code var dummy = JSROOT.Painter.getElementMainPainter(divid) but it just returns null.

I also tried doing it as it is written in the source code like this:

let tmp = JSROOT.ObjectPainter(divid);
var dummy = tmp.getMainPainter(True);

Here I get a object for the tmp but then tmp.getMainPainter gives just null.

I tried also function tmp.getObject() but it returns undefined.

Any help will very much be appreciated.


JSROOT Version: 6.0
Platform: Linux

Hi Andrej,

I need complete code to identify problem.
getElementMainPainter function should be working - it is used in different places of JSROOT itself.
May be you do not wait for JSROOT.draw completion?
It now returns Promise and one should wait until it is resolved.


1 Like

Maybe that is the problem, not waiting to draw. Because in previous verison I used callback.

I just tried to make it like this but the output is still null:

function initSliders(divid){
    var obj = JSROOT.Painter.getElementMainPainter(divid);
JSROOT.draw(divid, jsonobj, "hist").then(initSliders(divid), console.log("draw failed"));

I am sorry for not providing the whole code, but it is located in a bigger project.

Hi Andrej,

You have mistake, should be:

JSROOT.draw(divid, jsonobj, "hist").then(() => initSliders(divid), () => console.log("draw failed"));


Dear Sergey,

thank you very much, that solved the issue.