JSRoot - set axis range

Dear root-ers,

I’d like to create a TRatioPlot with JSRoot. The class doesn’t seem available.
As a workaround, I thought to make a second histo below the original, and with a setInterval call, to update the xAxis range of the one wrt the other.

However, I don’t find yet how to (programmatically in JS) set the range of the axis/histo.

Thanks for any tip

Hi Emil,

TRatioPlot is complicated class with several cross-references.
Therefore JSROOT does not provide method to create it.

I recommend to create it in the ROOT, store as JSON and then embed such JSON into JavaScript.
In such case you will be able to modify it to your need - including replacing of the content or changing axis labels.

Display of TRatioPlot should work. See several examples here:


Thanks Sergey,

for my current application, I handle objects directly online (online monitoring of histograms published in the experiment website), so I don’t really have an option for making ROOT files as it is; I could change the approach completely if all else fails.

Is there no way to handle the histo/canvas axis zoom from the xml object?

thanks again

You can create dummy TRatioPlot object with some default histograms once and reuse it every time you need to put some new data in.

I guess you mean to make the dummy TRatioPlot in a root file that I can access, and then, within the xml object, I can access the internal histos that are plotted, and set them to what I make in the js code?

If yes, I think it makes sense, will try in a bit.
If not, then, please explain a bit more; I haven’t (js)root-ed in a long while and am rusty

Also, could you please point to where one can download the example root files that are linked under

I can’t find them yet :slight_smile:
EDIT: found fiddling with the URL

thanks again

I recommend to generate JSON.

Just take any example like tutorials/hist/ratiplot5.C

Add as the last line: rp1->SaveAs("rp5.json");

Produced json insert into your code. Do not forget parse it:

import { parse } from 'https://root.cern/js/latest/modules/core.mjs';

let code =  
   // here should be content of rp5.json file

let obj = parse(code);

Hi Sergey

  1. maybe I miss something obvious, but I cannot find the tutorials folder. Would be nice to have a link in the main jsRoot pages

  2. Until I find the json one, I load the TCanvas of a TRatioPlot from the ratioplot.root file, and I see the xml, but I don’t see yet what needs to be set to use my own histograms in place of the ones in canvas
    I tried to set fH1 and fH2 under obj.fPrimitives.arr[3] (TRatioPlot), but it doesn’t change yet…)

thanks again

It is in $ROOTSYS/tutorials directory. You also can find them in the repository

That’s why I recommend to use JSON - there it is relatively clear how to access necessary objects and modify them.

1 Like

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