COREPLOT问题
-
19-09-2019 - |
题
我现在从核心图开始,遇到了一些问题。我遵循此页面的教程: http://www.switchonthecode.com/tutorials/usisher-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];
}
解决方案
您指出的示例已过时,不再与核心绘图框架的当前API匹配。我建议您从带有框架的示例应用程序(在示例目录中)开始,因为我们一直将其更新以匹配任何API更改。
例如 axisLabelOffset
已重命名为 labelOffset
, defaultPlotSymbol
不再存在(您设置了 plotSymbol
cpplot实例上的属性),情节空间不再具有 bounds
财产,您不再需要使用 -initWithFrame:
对于CPPLOT实例。
同样,只需将与框架一起运送的样品应用程序作为模板,然后从那里工作。我们尚未达到1.0释放,因此随着我们稳定并增强框架,API会发生变化。
其他提示
您正在遇到不兼容的类型错误,因为MajorInterVallengtth期望 NSDecimal
而且您正在返回 NSDecimalNumber
. 。看看这是否适合这些错误:
axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
对于其他人,您是否在某处包括标头文件?
set the header search and other link (Users..../framework & -ObjC respectively)
我想您正在提供绝对的道路。如果您浏览了Coreplot文档,您将看到他们清楚地提到了“您应该在标头搜索路径字段中提供相对路径”
了解什么是相对路径,”http://webdesign.about.com/od/beginningtutorials/a/aa040502a.htm"
如下所示,获取核心图的完整路径“ mdfind”。
在终端类型中,mdfind -name coreplot
将获得完整的路径名。
走完整的路径并插入标题搜索路径
以及上面...将-OBJC添加到“ Othetr Linker标志”中,并在“链接二进制与库”中添加Quartz框架工作
它将起作用:)
我做了以下操作:
1)添加#import“ coreplot-cocoatouch.h” 2)在.h vc文件中添加了:uiviewController 3)添加了Cptest App中的完全相同的代码4)在我的项目中添加了CorePlot-Cocoatouch框架目标设置,在项目设置中设置标题搜索和其他链接(分别为/框架和-OBJC),添加了QuartzCore框架,当我编译时,我会得到:
导入“ coreplot-cocoatouch.h”没有此类文件或目录。
我不明白为什么它找不到标题文件...