JSROOT Click on the histogram to obtain the histogram bin data

When I click on a bin in the histogram, how do I get the data for that bin? And print the data results through consolg.log(bindata). The printed result will look like the one in the red box.

My code is like this。

Hope I can get help with code examples。Thanks。

Hi and welcome to the forum!

I guess, you can try this example.

It shows how custom click or tooltip handler can be assigned.

Here is source code:


Uncaught (in promise) TypeError: painter.configureUserClickHandler is not a function

In my vscode, it prompts that configureUserClickHandler exists.


Why is this?

Although an error is reported in the chrome browser console: configureUserClickHandler is not a function. But by clicking I can get the correct result.

Can you try to use JSROOT.draw. But in principle it should be the same for the first time.

Using JSROOT.draw still prompts: Uncaught (in promise) TypeError: painter.configureUserClickHandler is not a function. Although I can get the correct results by clicking on it, I think this bug still needs to be fixed.

The above is a discussion of clicking a single bin. If I use the mouse to select an area on the histogram, how can I get all the data in this area? Mainly including x=[0.6912,0.7226], y=[1.021, 1.047). Thanks again for your answer.

Which JSROOT version you are using?

This functionality not exists while such area selection used only for zooming - no any tooltips are provided while zoom area is selected. After histogram is zoomed one could get access to actually selected bins and try to use it. Is it that you want?

1、The version of JSROOT I use is 7.4.1。
2、For example, I use the mouse to select an area in the histogram, and I want to get all the data in the red box area in the picture, mainly including x=[0.6912,0.7226], y=[1.021, 1.047) of all bins。

Strange. configureUserClickHandler was introduced in version 7.0. Have no idea why browser reports
such error. I need a reproducer to be able debug it.

As I explain, currently zooming is performed when such rectangle area is selected in JSROOT.
You can first do zooming and then try to count some statistic in zoomed area. As alternative,
you could redefine zoom method of the frame painter and try to do something else there. Like:

const frame_painter = painter.getFramePainter();
frame_painter.old_zoom = frame_painter.zoom;
frame_painter.zoom = function(...args) {
   if ((args[0] !== args[1]) && (args[2] !== args[3]) && (args[3] !== undefined)) {
      // handle zoom area when X and Y selected at the same time
      return true;
   return this.old_zoom(...args);

But then you have to be aware that all other kinds of zooming may not work.

And in any case you have to use some private methods of histogram painter to get statistic over the
zoom area. You can check TH1Painter.countStat method to get idea how it works.

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