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

**URL:** <https://root-forum.cern.ch/t/getmainpainter-divid-in-jsroot-v5-9-v6/43147>\
**Category:** Newbie\
**Tags:** jsroot\
**Created:** [January 18, 2021, 5:57pm UTC](https://root-forum.cern.ch/t/getmainpainter-divid-in-jsroot-v5-9-v6/43147 "2021-01-18T17:57:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndrejL](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/andrejl/32/23243_2.png) [@AndrejL](https://root-forum.cern.ch/u/AndrejL)\
**Post date:** [January 18, 2021, 5:57pm UTC](https://root-forum.cern.ch/t/getmainpainter-divid-in-jsroot-v5-9-v6/43147/1 "2021-01-18T17:57:25Z")

</div>

Hello,

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:

```auto
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.

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/7/d/7d4102c60c7f8ca79545690b560bcdb9413737e2.png)

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

Any help will very much be appreciated.

Cheers.  
Andrej

* * *

_JSROOT Version:_ 6.0  
_Platform:_ Linux

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [January 18, 2021, 6:21pm UTC](https://root-forum.cern.ch/t/getmainpainter-divid-in-jsroot-v5-9-v6/43147/2 "2021-01-18T18:21:24Z")

</div>

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.

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![AndrejL](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/andrejl/32/23243_2.png) [@AndrejL](https://root-forum.cern.ch/u/AndrejL)\
**Post date:** [January 18, 2021, 7:28pm UTC](https://root-forum.cern.ch/t/getmainpainter-divid-in-jsroot-v5-9-v6/43147/3 "2021-01-18T19:28:06Z")

</div>

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:

```auto
function initSliders(divid){
    fun1(divid);
    fun2(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.

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [January 19, 2021, 9:36am UTC](https://root-forum.cern.ch/t/getmainpainter-divid-in-jsroot-v5-9-v6/43147/4 "2021-01-19T09:36:51Z")

</div>

Hi Andrej,

You have mistake, should be:

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

```

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![AndrejL](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/andrejl/32/23243_2.png) [@AndrejL](https://root-forum.cern.ch/u/AndrejL)\
**Post date:** [January 19, 2021, 2:39pm UTC](https://root-forum.cern.ch/t/getmainpainter-divid-in-jsroot-v5-9-v6/43147/5 "2021-01-19T14:39:25Z")

</div>

Dear Sergey,

thank you very much, that solved the issue.

Cheers,  
Andrej
