I need a root macro that read values from a file and draw a piechart using them.
I don’t know -a priori- the number of slices, which can change from one file to another.
This is what I tried to do:
/*
* Draw a pie chart from input file. The input file must contain only
* 2 columns: value + label
*/
void pchart (string input)
{
string line;
string label;
double y;
size_t point = 0;
TCanvas *c = new TCanvas("c", "TPie", 500, 500);
TPie *pie = new TPie();
ifstream fileInput (input.c_str());
while (getline(fileInput, line)) {
if (line[0] == '#' || line[0] == '\0') continue;
stringstream(line) >> y >> label;
pie->SetEntryFillColor(point, point);
pie->SetEntryVal(point, y);
pie->SetEntryLabel(point, label.c_str());
point++;
}
pie->Draw("rsc");
}
A simple input file can be:
Blockquote
1 a
2 b
3 c
The above code produce an empty circle and only shows the first slice as if it were the only one (so it’s not a ‘slice’: it’s the entire pie).
This is something I can’t do, not in a short time for sure, at least. And by ‘short time’ I mean: I’d need maybe even ~1 month to get confident with the TPie class.