2012-04-04 14 views
2

私は、コアプロットフレームワークを使用して円グラフを実装しました。各スライス内にテキストを表示する方法を知る必要があります。ここで各スライスのpiechat内にテキストを表示する方法

は.Mのソースコードです:

@implementation ViewController 

@synthesize graph,pieData; 

// Implement loadView to create a view hierarchy programmatically 
// without using a nib. 
- (void)loadView { 
    CPTGraphHostingView * newView = [[CPTGraphHostingView alloc]initWithFrame: 
            [[UIScreen mainScreen] applicationFrame]]; 
    self.view = newView; 
    [newView release]; 
} 

// Implement viewDidLoad to do additional setup after loading the view, 
// typically from a nib. 
- (void)viewDidLoad { 
    [super viewDidLoad]; 

    graph = [[CPTXYGraph alloc] initWithFrame: self.view.bounds]; 
    CPTGraphHostingView *hostingView = (CPTGraphHostingView *)self.view; 
    hostingView.hostedGraph = graph; 

    CPTPieChart *pieChart = [[CPTPieChart alloc] init]; 
    pieChart.dataSource = self; 
    pieChart.delegate = self; 
    pieChart.pieRadius = 100.0; 
    pieChart.identifier = @"PieChart1"; 
    pieChart.startAngle = M_PI_4; 
    //pieChart.sliceDirection = CPTPieDirectionCounterClockwise; 
    pieChart.sliceDirection = CPTPieDirectionClockwise; 

    self.pieData= [NSMutableArray arrayWithObjects: 
        [NSNumber numberWithDouble:90.0], 
        [NSNumber numberWithDouble:20.0], 
        [NSNumber numberWithDouble:30.0], 
        [NSNumber numberWithDouble:40.0], 
        [NSNumber numberWithDouble:50.0], 
        [NSNumber numberWithDouble:60.0], 
        nil]; 

    CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme]; 
    [graph applyTheme:theme]; 

    [graph addPlot:pieChart]; 
    [pieChart release]; 
} 


-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot { 
    return [self.pieData count]; 
} 

-(NSNumber *)numberForPlot:(CPTPlot *)plot 
field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index { 
    return [self.pieData objectAtIndex:index]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
} 

- (void)viewDidUnload { 
} 

- (void)dealloc { 
    [pieData release]; 
    [graph release]; 
    [super dealloc]; 
} 

- (void)pieChart:(CPTPieChart *)plot 
sliceWasSelectedAtRecordIndex:(NSUInteger)index { 
    NSLog(@"Slices are selected: index = %d", index); 
} 
@end 

答えて

0

labelOffsetプロパティを使用します。正の値を指定すると、プロットの外側にラベルが配置され、負の値を指定するとラベルが内側に配置されます。

関連する問題