ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
piechart.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphics
3 /// Pie chart example.
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \authors Olivier Couet, Guido Volpi
9 
10 void piechart()
11 {
12  Float_t vals[] = {.2,1.1,.6,.9,2.3};
13  Int_t colors[] = {2,3,4,5,6};
14  Int_t nvals = sizeof(vals)/sizeof(vals[0]);
15 
16  TCanvas *cpie = new TCanvas("cpie","TPie test",700,700);
17  cpie->Divide(2,2);
18 
19  TPie *pie1 = new TPie("pie1",
20  "Pie with offset and no colors",nvals,vals);
21  TPie *pie2 = new TPie("pie2",
22  "Pie with radial labels",nvals,vals,colors);
23  TPie *pie3 = new TPie("pie3",
24  "Pie with tangential labels",nvals,vals,colors);
25  TPie *pie4 = new TPie("pie4",
26  "Pie with verbose labels",nvals,vals,colors);
27 
28  cpie->cd(1);
29  pie1->SetAngularOffset(30.);
30  pie1->SetEntryRadiusOffset( 4, 0.1);
31  pie1->SetRadius(.35);
32  pie1->Draw("3d");
33 
34  cpie->cd(2);
35  pie2->SetEntryRadiusOffset(2,.05);
36  pie2->SetEntryLineColor(2,2);
37  pie2->SetEntryLineWidth(2,5);
38  pie2->SetEntryLineStyle(2,2);
39  pie2->SetEntryFillStyle(1,3030);
40  pie2->SetCircle(.5,.45,.3);
41  pie2->Draw("rsc");
42 
43  cpie->cd(3);
44  pie3->SetY(.32);
45  pie3->GetSlice(0)->SetValue(.8);
46  pie3->GetSlice(1)->SetFillStyle(3031);
47  pie3->SetLabelsOffset(-.1);
48  pie3->Draw("3d t nol");
49  TLegend *pieleg = pie3->MakeLegend();
50  pieleg->SetY1(.56); pieleg->SetY2(.86);
51 
52  cpie->cd(4);
53  pie4->SetRadius(.2);
54  pie4->SetLabelsOffset(.01);
55  pie4->SetLabelFormat("#splitline{%val (%perc)}{%txt}");
56  pie4->Draw("nol <");
57 }
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:35
float Float_t
Definition: RtypesCore.h:53
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
void SetAngularOffset(Double_t)
Set the global angular offset for slices in degree [0,360].
Definition: TPie.cxx:1191
int Int_t
Definition: RtypesCore.h:41
TPieSlice * GetSlice(Int_t i)
Return the reference to the slice of index 'id'.
Definition: TPie.cxx:712
virtual void SetFillStyle(Style_t fstyle)
Definition: TAttFill.h:52
void SetEntryFillStyle(Int_t, Int_t)
Set the fill style for the "i" slice.
Definition: TPie.cxx:1260
virtual void SetY2(Double_t y2)
Set the Y2 value.
Definition: TPave.cxx:669
void SetEntryRadiusOffset(Int_t, Double_t)
Set the distance, in the direction of the radius of the slice.
Definition: TPie.cxx:1268
void SetY(Double_t)
Set Y value.
Definition: TPie.cxx:1397
void SetValue(Double_t)
Set the value for this slice.
Definition: TPieSlice.cxx:108
void SetCircle(Double_t x=.5, Double_t y=.5, Double_t rad=.4)
Set the coordinates of the circle that describe the pie:
Definition: TPie.cxx:1208
The Canvas class.
Definition: TCanvas.h:48
virtual void SetY1(Double_t y1)
Set the Y1 value.
Definition: TPave.cxx:656
void SetRadius(Double_t)
Set the pie chart's radius' value.
Definition: TPie.cxx:1367
Draw a Pie Chart,.
Definition: TPie.h:31
TLegend * MakeLegend(Double_t x1=.65, Double_t y1=.65, Double_t x2=.95, Double_t y2=.95, const char *leg_header="")
This method create a legend that explains the contents of the slice for this pie-chart.
Definition: TPie.cxx:768
void SetLabelsOffset(Float_t)
Set the distance between the label end the external line of the TPie.
Definition: TPie.cxx:1351
void SetLabelFormat(const char *)
This method is used to customize the label format.
Definition: TPie.cxx:1314
void SetEntryLineStyle(Int_t, Int_t)
Set the style for the slice's outline. "i" is the slice number.
Definition: TPie.cxx:1236
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1073
void SetEntryLineColor(Int_t, Int_t)
Set the color for the slice's outline. "i" is the slice number.
Definition: TPie.cxx:1228
void SetEntryLineWidth(Int_t, Int_t)
Set the width of the slice's outline. "i" is the slice number.
Definition: TPie.cxx:1244
virtual void Draw(Option_t *option="l")
Draw the pie chart.
Definition: TPie.cxx:274