0
votes

Am trying out a simple Pie Chart with Core Plot in an iPhone App. I want to plot a value, which is the percentage of CPU used. In the method 'numberForPlot', here is what I have written

-(NSNumber *) numberForPlot:(CPTPlot *)plot
                  field:(NSUInteger)fieldEnum
            recordIndex:(NSUInteger)index {

    Health_Cpu *healthData = (Health_Cpu *) [dictHealth objectForKey:[self.arrayHealthKeys objectAtIndex:0]];
    if (CPTPieChartFieldSliceWidth == fieldEnum) {
        return [NSNumber numberWithFloat:healthData.cpuUsage]; // In Percentage
    }
}

How do I tell Core Plot that this is a percentage value (i.e. if the value is 25.0, then it has to plot it as 25% i.e. color 1/4th of the pie chart)? Now, it is taking it as an absolute number. So what I have done is to return two values from numberForPlot, one being the value, and the other being (100-value).

1
Are you asking how to make a slice that covers 1/4 of the pie, or how to label the slices with percentages? - Eric Skroch
Hi Eric, My question is the former : "how to make a slice that covers 1/4 of the pie"? (how to tell core plot that the number 25 am returning from numberForPlot() is a percentage & not an absolute number? - Jean

1 Answers

0
votes

To make a slice width of 25.0 take up 1/4 of the pie, the other slices should total 75.0. Each slice takes up a fraction of the full circle computed by x / sum(x) where x is the slice width value and sum(x) is the sum of the widths of all pie slices.

Alternatively, set the startAngle and endAngle of the pie chart. All of the slices will be drawn between those two angles, sized proportional to their values. This should work with only one slice which can have any value.