Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
piechart.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphics
3 /// \notebook
4 /// Pie chart example.
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \authors Olivier Couet, Guido Volpi
10 
11 void 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",
21  "Pie with offset and no colors",nvals,vals);
22  TPie *pie2 = new TPie("pie2",
23  "Pie with radial labels",nvals,vals,colors);
24  TPie *pie3 = new TPie("pie3",
25  "Pie with tangential labels",nvals,vals,colors);
26  TPie *pie4 = new TPie("pie4",
27  "Pie with verbose labels",nvals,vals,colors);
28 
29  cpie->cd(1);
30  pie1->SetAngularOffset(30.);
31  pie1->SetEntryRadiusOffset( 4, 0.1);
32  pie1->SetRadius(.35);
33  pie1->Draw("3d");
34 
35  cpie->cd(2);
36  pie2->SetEntryRadiusOffset(2,.05);
37  pie2->SetEntryLineColor(2,2);
38  pie2->SetEntryLineWidth(2,5);
39  pie2->SetEntryLineStyle(2,2);
40  pie2->SetEntryFillStyle(1,3030);
41  pie2->SetCircle(.5,.45,.3);
42  pie2->Draw("rsc");
43 
44  cpie->cd(3);
45  pie3->SetY(.32);
46  pie3->GetSlice(0)->SetValue(.8);
47  pie3->GetSlice(1)->SetFillStyle(3031);
48  pie3->SetLabelsOffset(-.1);
49  pie3->Draw("3d t nol");
50  TLegend *pieleg = pie3->MakeLegend();
51  pieleg->SetY1(.56); pieleg->SetY2(.86);
52 
53  cpie->cd(4);
54  pie4->SetRadius(.2);
55  pie4->SetLabelsOffset(.01);
56  pie4->SetLabelFormat("#splitline{%val (%perc)}{%txt}");
57  pie4->Draw("nol <");
58 }