0

我在 iPhone 应用程序中尝试使用 Core Plot 制作一个简单的饼图。我想绘制一个值,它是 CPU 使用的百分比。在“numberForPlot”方法中,这是我写的

-(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
    }
}

我如何告诉 Core Plot 这是一个百分比值(即,如果该值为 25.0,那么它必须将其绘制为 25%,即饼图的颜色 1/4)?现在,它把它当作一个绝对数字。所以我所做的是从 numberForPlot 返回两个值,一个是值,另一个是(100 值)。

4

1 回答 1

0

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.

于 2013-07-05T03:53:43.327 回答