yepes
1
I am using jsroot for plotting several plots. I use Multigraph.
I define a Multigraph with:
var mgraph = JSROOT.CreateTMultiGraph(obj);
where I add a TGraph obj. Then I want to add other TGraphs:
- I tried mgraph.Add(ojb2), but it complained.Then I used:
mgraph[‘fGraphs’].arr.push(obj2);
following some other post, and it works:
However, I cannot figure out how to add the options to plot obj1 or ojb2. I want to plot obj with a line (histo) and obj2 with makers (“p”).
Any help would be appreciated.
Thanks,
Pablo Yepes
Hi,
See for example: root.cern.ch/js/latest/demo/multigraph.htm
[code] var npoints = 20;
var xpts=[];
var ypts=[];
for (var i=0; i<npoints; i++) {
switch(cnt%2) {
case 1 : xpts.push(i); ypts.push(5i); break;
default: xpts.push(i); ypts.push(i); break;
}
}
var graph1 = JSROOT.CreateTGraph(npoints, xpts, ypts);
graph1.fLineColor = 2;
graph1.fMarkerSize = 2;
xpts = [];
ypts = [];
for (i=0; i<npoints; i++) {
switch(cnt%2) {
case 1 : xpts.push(i); ypts.push(ii); break;
default: xpts.push(i); ypts.push(Math.sqrt(i)); break;
}
}
var graph2 = JSROOT.CreateTGraph(npoints, xpts, ypts);
graph2.fLineColor = 3;
graph2.fMarkerSize = 2;
var mgraph = JSROOT.CreateTMultiGraph(graph1, graph2);
mgraph.fTitle = "Drawing " + cnt++;
// set fixed Y-range if required
// mgraph.fMinimum = 0;
// mgraph.fMaximum = 400;
JSROOT.redraw('object_draw', mgraph);[/code]
Cheers, Bertrand
linev
3
Hi,
If you need to set draw options for TGraph objects,
you need to construct TMultiGraph object yourself.
If you look in the JSROOT source code, it is not that difficult:
github.com/linev/jsroot/blob/ma … 1399-L1404
In your case:
var mgraph = JSROOT.Create("TMultiGraph");
mgraph.fGraphs.Add(graph1, "L");
mgraph.fGraphs.Add(graph2, "P");
I hope, this will help.
Regards,
Sergey