Hi experts,
Is is possible to add a title to my TLegend in JSROOT. For instance if I wanted to add a title to the legend here:
https://root.cern.ch/js/latest/api.htm#custom_html_tlegend
As a bonus, I don’t suppose it’s possible to create a TPaveText object in native JSROOT?
-Mark
linev
2
Hi Mark,
Title in TLegend is just first entry, which does not have associated object. In mentioned example you can just create such header, calling:
leg.fPrimitives.Add(CreateLegendEntry(null, "TLegend title"));
leg.fPrimitives.Add(CreateLegendEntry(graph1, "Math.sin " + cnt));
leg.fPrimitives.Add(CreateLegendEntry(graph2, "Math.cos " + cnt));
It is possible to create TPaveText
object in JSROOT. Just do:
var pt = JSROOT.Create("TPaveText");
pt.fName = "anyName";
pt.AddText("Any text");
Regards,
Sergey
1 Like
Thank you Sergey!
Only issue is that this draws a little black line next to the legend title as if it were the label for some nonexistent line.
-Mark
linev
4
There is simple solution. You need to modify function:
function CreateLegendEntry(obj, lbl, opt) {
var entry = JSROOT.Create("TLegendEntry");
entry.fObject = obj;
entry.fLabel = lbl;
entry.fOption = opt || "l";
return entry;
}
and when calling it:
leg.fPrimitives.Add(CreateLegendEntry(null, "TLegend title","h"));
leg.fPrimitives.Add(CreateLegendEntry(graph1, "Math.sin " + cnt));
leg.fPrimitives.Add(CreateLegendEntry(graph2, "Math.cos " + cnt));
Thank you! That works perfectly. And thank you for this great tool.
system
Closed
6
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.