我正在尝试在我的OSX项目中设置一个简单的饼图,在Xcode 5中,遵循以下教程:http://www.raywenderlich.com/13269/how-to-draw-graphs-with-core-plot-part-1。
问题是图表没有显示,CPTGraphHostingView和CPTXYGraph的高度和宽度均为0.00。
这是我使用的代码,之后我应该能够在视图中看到图形的标题。 hostView是对xib文件中NSView的引用。
-(void)configureHost {
self.graphHostingView = [(CPTGraphHostingView *)[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 0, 1103, 532)];
NSLog(@"%f", self.graphHostingView.frame.size.width);
[hostView addSubview:self.graphHostingView];
}
-(void)configureGraph {
NSRect parentRect = CGRectMake(0, 0, 1103, 532);
//create graph
CPTGraph *graph = [[CPTXYGraph alloc] init];
[graph setFrame:parentRect];
NSLog(@"%f", graph.frame.size.width);
self.graphHostingView.hostedGraph = graph;
graph.paddingBottom = 0.0f;
graph.paddingLeft = 0.0f;
graph.paddingTop = 0.0f;
graph.paddingRight = 0.0f;
graph.axisSet = nil;
//text in graph
CPTMutableTextStyle *textStlye = [CPTMutableTextStyle textStyle];
textStlye.color = [CPTColor grayColor];
textStlye.fontName = @"Helvetica-Bold";
textStlye.fontSize = 16.0f;
//graph title
graph.title = @"Title";
graph.titleTextStyle = textStlye;
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
graph.titleDisplacement = CGPointMake(0.0f, -12.0f);
self.theme = [CPTTheme themeNamed:kCPTPlainWhiteTheme];
}
不那么重要,但是当我使用kCPTPlainWhiteTheme const或其他主题consts时,我也会收到错误。线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x0)。
这可能是一个明显的问题,但我无法看到它。 提前谢谢。