# Issues with displaying TH1s on JSROOT on webpages

**URL:** <https://root-forum.cern.ch/t/issues-with-displaying-th1s-on-jsroot-on-webpages/64312>\
**Category:** ROOT\
**Tags:** jsroot\
**Created:** [October 13, 2025, 9:24am UTC](https://root-forum.cern.ch/t/issues-with-displaying-th1s-on-jsroot-on-webpages/64312 "2025-10-13T09:24:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaan\_Guven](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kaan_guven/32/34986_2.png) [@Kaan\_Guven](https://root-forum.cern.ch/u/Kaan_Guven)\
**Post date:** [October 13, 2025, 9:24am UTC](https://root-forum.cern.ch/t/issues-with-displaying-th1s-on-jsroot-on-webpages/64312/1 "2025-10-13T09:24:12Z")

</div>

Hi!

I experienced some problems when I tried to create a ROOT Browser page on my personal CERN home page. I attempted to integrate it with my plot browser that you can see here:

[https://guven.web.cern.ch/test\_jsroot](https://guven.web.cern.ch/test_jsroot)

This calls `viewroot.php` script when I click on the ROOT files, which I tried my best to code with ChatGPT, but I couldn’t make it work unfortunately. If you click on the page you will see 3 root files in plots section. ntuple works flawlessly, however the other ones contain TH1s instead of ntuples, and for some reason they don’t work.

I tried multiple times and couldn’t succeed. Now I started believe it has something to do with the histograms. Do you know what the source of this error could be?

A copy of my viewroot.php script is given here: [https://guven.web.cern.ch/test\_jsroot/viewroot.newphp](https://guven.web.cern.ch/test_jsroot/viewroot.newphp)

My goal was to create a plot browser page like this: [https://cms-plt.web.cern.ch/cms-plt/paper/Paper](https://cms-plt.web.cern.ch/cms-plt/paper/Paper)

And also add the functionality to browse individual ROOT files containing histograms.

If you have the time could you help me with that please? I feel I am close, but I cannot finish it myself.

N.B.

- The site is hosted at CERN, so I might not have full control on all open ports, security etc. If the problem is related to the configuration of the page I cannot do anything unfortunately, but I am not sure of this.
- My knowledge of php and javascript is quite limited. I would be happy if you try to be explicit in solving the problem.

Thanks in advance!

Cheers.

---

<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:** [October 13, 2025, 9:31am UTC](https://root-forum.cern.ch/t/issues-with-displaying-th1s-on-jsroot-on-webpages/64312/2 "2025-10-13T09:31:09Z")

</div>

Hi,

> [@Kaan\_Guven](#):
>
> My goal was to create a plot browser page like this: [PlotBrowser](https://cms-plt.web.cern.ch/cms-plt/paper/Paper)

May be start from this point.  
If you want to show some concrete plot on HTML page - you should not create `HierarchyPainter` which provides browsing in ROOT files and let you display any object from it. And may be you just need to use `draw` function of JSROOT like it shown in this demo:

> **[Reading object from the ROOT file](https://root.cern/js/latest/demo/read_file.htm)**

Code is very simple there:

```auto
   import { openFile, draw } from 'jsroot';
   const file = await openFile('../../files/hsimple.root');
   const obj = await file.readObject('hpxpy;1');
   draw('drawing', obj, 'colz');

```

Of course, all kinds of other HTML elements can be add as well.

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![Kaan\_Guven](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kaan_guven/32/34986_2.png) [@Kaan\_Guven](https://root-forum.cern.ch/u/Kaan_Guven)\
**Post date:** [October 13, 2025, 9:36am UTC](https://root-forum.cern.ch/t/issues-with-displaying-th1s-on-jsroot-on-webpages/64312/3 "2025-10-13T09:36:26Z")

</div>

Dear Sergey,

Thank you for your message.

Of course that is an option, however I am still curious how one can browse ROOT files and see the histograms on the right pane. I think it is an amazing thing to be able to do this on simple webpages.

Do you have any opinions why this page does not show TH1s, but show ntuples?

Best,

Kaan

---

<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:** [October 13, 2025, 10:39am UTC](https://root-forum.cern.ch/t/issues-with-displaying-th1s-on-jsroot-on-webpages/64312/4 "2025-10-13T10:39:43Z")

</div>

Hi Kaan,

> Do you have any opinions why this page does not show TH1s, but show ntuples?

There are several issues with your code.

First of all, expand function is async, so one need to wait for it:

```auto
      await h.exapndToLevel(2);

```

But I do not recommend to use this function. It automatically loads all objects from the file and try to expand them - which can take a while. Also JSROOT changes it behavior when object was tried to expand.

And then iterating over the items was not correct. One can do:

```auto
      let first = null;
      h.forEachItem(item => {
         if ((item?._kind === 'ROOT.TH1F') && !first)
            first = h.itemFullName(item);
      });
      if (first)
         await h.display(first);

```

Regards,  
Sergey

---

<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:** [October 13, 2025, 10:41am UTC](https://root-forum.cern.ch/t/issues-with-displaying-th1s-on-jsroot-on-webpages/64312/5 "2025-10-13T10:41:28Z")

</div>

Also small remark - it is not allowed to use `async` function inside `h.forEachItem`.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [October 27, 2025, 10:42am UTC](https://root-forum.cern.ch/t/issues-with-displaying-th1s-on-jsroot-on-webpages/64312/6 "2025-10-27T10:42:17Z")

</div>

Closed on October 27, 2025, 10:42am UTC

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