JSRoot drawing THStack

Hi,
I would like to draw in JSroot two histograms in stack. I don’t use ROOT files. My files are directly incorporated into code of page (so I have setBinContent and so one).
There is one problem - I cannot use THStack, I can only draw one of those histograms. How can I create THStack? There is no function that provide this but I saw some examples on page.

Hi,

There are several examples how to create and update TMultiGraph class. Like :

root.cern/js/latest/demo/multigraph.htm
root.cern/js/latest/demo/multigraph_legend.htm

Similar approach can be applied for THStack.
Problem, that JSROOT does not provide function to create THStack object -
you should do it yourself.

var stack = JSROOT.Create("TNamed");
stack._typename = "THStack";
stack.fHistogram = JSROOT.CreateTH1(10); // one should set axis attributes
stack.fMinimum = stack.fMaximum = -1111;
stack.fHists = JSROOT.Create("TList");
for (var n=0;n<5;n++) {
   var hist = JSROOT.CreateTH1(10);
   hist.Fill(n*2,10);
   hist.fLineColor = n+2;
   stack.fHists.Add(hist);
}
JSROOT.draw("your_divid", stack,"");

Or jsroot.gsi.de/dev/demo/thstack.htm

Regards,
Sergey

Thank you, now it works.
Btw. where I can find more “no-file” examples. I can’t find this example listed on jsroot.gsi.de/.

Hi,

All such examples posted here:

jsroot.gsi.de/latest/api.htm or
root.cern/js/latest/api.htm

Regards,
Sergey

I also add support of THStack creation to current dev version.

Now one could use:

   var stack = JSROOT.Create("THStack");

    for (var n=0;n<5;n++) {
        var hist = JSROOT.CreateTH1(10);
        hist.fName ="hist"+n;
        hist.Fill(n*2,10);
        hist.fLineColor = n+2;
        stack.fHists.Add(hist);
     }

  JSROOT.draw("object_draw", stack, "");