【问题标题】:how to display the texts inside the piechat each slices如何在每个切片的饼图中显示文本
【发布时间】:2012-04-04 06:46:40
【问题描述】:

我已经使用核心绘图框架实现了一个饼图,我需要知道如何在每个切片内显示文本。

这是.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

【问题讨论】:

    标签: iphone objective-c ios core-plot pie-chart


    【解决方案1】:

    使用labelOffset 属性。正值会将标签定位在绘图之外,负值会将它们定位在绘图内部。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多