我现在开始使用核心情节,并遇到了一些问题。我按照本页面的教程进行了操作:http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application
并按照此页面的说明完成:http://code.google.com/p/core-plot/wiki/UsingCorePlotInApplications(例如-all_load)。
但我仍有一些问题,我收到以下错误:
error: incompatible type for argument 1 of 'setMajorIntervalLength:'
error: request for member 'axisLabelOffset' in something not a structure or union
error: incompatible type for argument 1 of 'setMajorIntervalLength:'
error: request for member 'axisLabelOffset' in something not a structure or union
error: request for member 'bounds' in something not a structure or union
error: request for member 'defaultPlotSymbol' in something not a structure or union
error: request for member 'bounds' in something not a structure or union
有谁知道我做错了什么? 这是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds];
CPLayerHostingView *hostingView = (CPLayerHostingView *)self.view;
hostingView.hostedLayer = graph;
graph.paddingLeft = 20.0;
graph.paddingTop = 20.0;
graph.paddingRight = 20.0;
graph.paddingBottom = 20.0;
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6)
length:CPDecimalFromFloat(12)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5)
length:CPDecimalFromFloat(30)];
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
CPLineStyle *lineStyle = [CPLineStyle lineStyle];
lineStyle.lineColor = [CPColor blackColor];
lineStyle.lineWidth = 2.0f;
axisSet.xAxis.majorIntervalLength = [NSDecimalNumber decimalNumberWithString:@"5"];
axisSet.xAxis.minorTicksPerInterval = 4;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.minorTickLineStyle = lineStyle;
axisSet.xAxis.axisLineStyle = lineStyle;
axisSet.xAxis.minorTickLength = 5.0f;
axisSet.xAxis.majorTickLength = 7.0f;
axisSet.xAxis.axisLabelOffset = 3.0f;
axisSet.yAxis.majorIntervalLength = [NSDecimalNumber decimalNumberWithString:@"5"];
axisSet.yAxis.minorTicksPerInterval = 4;
axisSet.yAxis.majorTickLineStyle = lineStyle;
axisSet.yAxis.minorTickLineStyle = lineStyle;
axisSet.yAxis.axisLineStyle = lineStyle;
axisSet.yAxis.minorTickLength = 5.0f;
axisSet.yAxis.majorTickLength = 7.0f;
axisSet.yAxis.axisLabelOffset = 3.0f;
CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc]
initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
xSquaredPlot.identifier = @"X Squared Plot";
xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];
xSquaredPlot.dataSource = self;
[graph addPlot:xSquaredPlot];
CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
xSquaredPlot.defaultPlotSymbol = greenCirclePlotSymbol;
CPScatterPlot *xInversePlot = [[[CPScatterPlot alloc]
initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
xInversePlot.identifier = @"X Inverse Plot";
xInversePlot.dataLineStyle.lineWidth = 1.0f;
xInversePlot.dataLineStyle.lineColor = [CPColor blueColor];
xInversePlot.dataSource = self;
[graph addPlot:xInversePlot];
}
答案 0 :(得分:10)
您指向的示例已过期,不再与Core Plot框架的当前API匹配。我建议从框架附带的示例应用程序开始(在示例目录中),因为我们保留了更新以匹配任何API更改。
例如,axisLabelOffset
已重命名为labelOffset
,defaultPlotSymbol
不再存在(您在CPPlot实例上设置plotSymbol
属性),绘图空间不再具有bounds
属性,您不再需要将-initWithFrame:
用于CPPlot实例。
再次,只需使用框架附带的示例应用程序作为模板,然后从那里开始工作。我们尚未达到1.0版本,因此我们会在稳定和增强框架时改变API。
答案 1 :(得分:3)
您收到了不兼容的类型错误,因为majorIntervalLength需要NSDecimal
并且您返回NSDecimalNumber
。看看这是否适用于那些错误:
axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
对于其他人你在哪里包括头文件?
答案 2 :(得分:1)
set the header search and other link (Users..../framework & -ObjC respectively)
我猜你提供绝对路径。如果你浏览corePlot文档,你会发现他们已经明确提到“你应该在Header Search path Field给出相对路径”
了解相关路径是什么, “http://webdesign.about.com/od/beginningtutorials/a/aa040502a.htm”
答案 3 :(得分:0)
通过终端命令“mdfind”获取core-plot的完整路径,如下所示。
在终端类型中,mdfind -name coreplot
将获得完整的路径名称。
采取完整路径并插入HEADERS SEARCH PATH
以及...将-Objc添加到“Othetr Linker Flags”并在“Link Binary With Libraries”中添加Quartz框架工作
它会工作:)
答案 4 :(得分:-1)
我做了以下事情:
1)添加了#import“CorePlot-CocoaTouch.h” 2)将:UIViewController添加到.h vc文件中 3)从CPTest app添加完全相同的代码 4)将coreplot-cocoatouch框架添加到我的项目中,在目标设置中设置依赖关系,在项目设置中设置标题搜索和其他链接(Users .... / framework& -ObjC),添加QuartzCore框架以及何时我编译得到:
我不明白为什么它找不到头文件...