Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
piechart.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphics
3/// \notebook
4/// \preview Pie chart example.
5///
6/// \macro_image
7/// \macro_code
8///
9/// \authors Olivier Couet, Guido Volpi
10
11void piechart()
12{
13 Float_t vals[] = {.2, 1.1, .6, .9, 2.3};
14 Int_t colors[] = {2, 3, 4, 5, 6};
15 Int_t nvals = sizeof(vals) / sizeof(vals[0]);
16
17 TCanvas *cpie = new TCanvas("cpie", "TPie test", 700, 700);
18 cpie->Divide(2, 2);
19
20 TPie *pie1 = new TPie("pie1", "Pie with offset and no colors", nvals, vals);
21 TPie *pie2 = new TPie("pie2", "Pie with radial labels", nvals, vals, colors);
22 TPie *pie3 = new TPie("pie3", "Pie with tangential labels", nvals, vals, colors);
23 TPie *pie4 = new TPie("pie4", "Pie with verbose labels", nvals, vals, colors);
24
25 cpie->cd(1);
26 pie1->SetAngularOffset(30.);
27 pie1->SetEntryRadiusOffset(4, 0.1);
28 pie1->SetRadius(.35);
29 pie1->Draw("3d");
30
31 cpie->cd(2);
32 pie2->SetEntryRadiusOffset(2, .05);
33 pie2->SetEntryLineColor(2, 2);
34 pie2->SetEntryLineWidth(2, 5);
35 pie2->SetEntryLineStyle(2, 2);
36 pie2->SetEntryFillStyle(1, 3030);
37 pie2->SetCircle(.5, .45, .3);
38 pie2->Draw("rsc");
39
40 cpie->cd(3);
41 pie3->SetY(.32);
42 pie3->GetSlice(0)->SetValue(.8);
43 pie3->GetSlice(1)->SetFillStyle(3031);
44 pie3->SetLabelsOffset(-.1);
45 pie3->Draw("3d t nol");
46 TLegend *pieleg = pie3->MakeLegend();
47 pieleg->SetY1(.56);
48 pieleg->SetY2(.86);
49
50 cpie->cd(4);
51 pie4->SetRadius(.2);
52 pie4->SetLabelsOffset(.01);
53 pie4->SetLabelFormat("#splitline{%val (%perc)}{%txt}");
54 pie4->Draw("nol <");
55}
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Color * colors
Definition X3DBuffer.c:21
The Canvas class.
Definition TCanvas.h:23
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
Draw a Pie Chart,.
Definition TPie.h:23