# Auto refresh plot with JSRoot

**URL:** <https://root-forum.cern.ch/t/auto-refresh-plot-with-jsroot/63546>\
**Category:** ROOT\
**Tags:** jsroot\
**Created:** [May 13, 2025, 3:04pm UTC](https://root-forum.cern.ch/t/auto-refresh-plot-with-jsroot/63546 "2025-05-13T15:04:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jb023](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/7c8e57/32.png) [@jb023](https://root-forum.cern.ch/u/jb023)\
**Post date:** [May 13, 2025, 3:04pm UTC](https://root-forum.cern.ch/t/auto-refresh-plot-with-jsroot/63546/1 "2025-05-13T15:04:53Z")

</div>

Hi, Let’s say I want to do a 100% custom UI in HTM+CSS+JS with JSROOT, and load data from a server. I would like to auto refresh the display every second in the case data has changed, with some basic polling:

This works:

```auto
<html>
<body>
<div id="container" style="width:600px; height:400px; border:1px solid gray;"></div>
<script type='module'>
import { httpRequest, draw } from 'https://root.cern/js/latest/modules/main.mjs';
const drawNow = () => {
    document.getElementById("container").innerHTML = "";    
    httpRequest("http://localhost:8080/graph1/Graph/root.json", "object").then((obj) => { return draw("container", obj, "colz"); });
}
const refresh = () => { // basic polling
    drawNow();    
    setTimeout(refresh, 1000);
}
refresh();
</script>
</body>
</html>

```

but `document.getElementById("container").innerHTML = ""` causes a white screen flickering. On the other hand, if I don’t “clear” like this, the new data points are overwritten on the same plot axis, which is not ok either. How to do this properly?  
(i.e. clear the data points (but not redraw the axis), and redraw only the new points)

Thanks!

---

<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:** [May 13, 2025, 3:13pm UTC](https://root-forum.cern.ch/t/auto-refresh-plot-with-jsroot/63546/2 "2025-05-13T15:13:24Z")

</div>

Hi,

Did you try [redraw](https://root.cern/js/latest/jsdoc/global.html#redraw) method of JSROOT?  
It designed exactly for this and you not need to use `innerHTML = ""`.

Also you can simply use URL:

`http://localhost:8080/graph1/Graph/draw.htm?monitoring=1000`

To constantly update object drawing.  
Some info you can find in [jsroot docu](https://github.com/root-project/jsroot/blob/master/docs/JSROOT.md#jsroot-with-thttpserver)

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![jb023](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/7c8e57/32.png) [@jb023](https://root-forum.cern.ch/u/jb023)\
**Post date:** [May 13, 2025, 3:27pm UTC](https://root-forum.cern.ch/t/auto-refresh-plot-with-jsroot/63546/3 "2025-05-13T15:27:29Z")

</div>

Thanks, `redraw` works indeed.

> you can simply use URL:  
> [http://localhost:8080/graph1/Graph/draw.htm?monitoring=1000](http://localhost:8080/graph1/Graph/draw.htm?monitoring=1000)  
> To constantly update object drawing.

Yes but I need to have the auto-refreshing plot in a specific div container in one part of a self-made custom HTML/CSS/JS interface, so this solution is not adapted, is that right? (except with an `iframe` but it seems I don’t really need an iframe for now)

---

<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:** [May 13, 2025, 3:33pm UTC](https://root-forum.cern.ch/t/auto-refresh-plot-with-jsroot/63546/4 "2025-05-13T15:33:04Z")

</div>

If `httpRequest` and `redraw` works for you - then it is most straightforward solution for you.

`draw.htm` can be used in `iframe` - if necessary.  
And one also can check how [`draw.htm` implemented](https://github.com/root-project/jsroot/blob/master/files/draw.htm).

---

<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:** [May 27, 2025, 3:33pm UTC](https://root-forum.cern.ch/t/auto-refresh-plot-with-jsroot/63546/5 "2025-05-27T15:33:34Z")

</div>

Closed on May 27, 2025, 3:33pm UTC

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