2

我现在从 core-plot 开始,遇到了一些问题。我按照此页面上的教程进行操作: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];
}
4

5 回答 5

10

您指向的示例已过时,不再与 Core Plot 框架的当前 API 匹配。我建议从框架附带的示例应用程序开始(在示例目录中),因为我们已经更新了这些应用程序以匹配任何 API 更改。

例如axisLabelOffset已重命名为labelOffsetdefaultPlotSymbol不再存在(您plotSymbol在 CPPlot 实例上设置属性),绘图空间不再具有bounds属性,并且您不再需要-initWithFrame:用于 CPPlot 实例。

同样,只需使用框架附带的示例应用程序作为模板,然后从那里开始工作。我们还没有发布 1.0 版本,所以随着我们稳定和增强框架,API 会发生变化。

于 2009-12-11T21:00:20.057 回答
3

您收到不兼容的类型错误,因为 majorIntervalLength 需要 aNSDecimal并且您正在返回 a NSDecimalNumber。看看这是否适用于这些错误:

axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];

对于其他人,您是否在某处包含头文件?

于 2009-12-11T19:32:16.297 回答
1
set the header search and other link (Users..../framework & -ObjC respectively) 

我猜你提供的是绝对路径。如果您浏览 corePlot 文档,您会看到他们明确提到“您应该在标题搜索路径字段中提供相对路径”

要了解什么是相对路径,请遵循“ http://webdesign.about.com/od/beginningtutorials/a/aa040502a.htm

于 2010-08-30T06:27:16.740 回答
0

通过终端命令“mdfind”获取 core-plot 的完整路径,如下所示。

在终端类型中, mdfind -name coreplot

将获得完整的路径名。

获取完整路径并插入 HEADERS SEARCH PATH

连同上面...将 -Objc 添加到“Othetr Linker Flags”并在“Link Binary With Libraries”中添加 Quartz 框架

它会工作:)

于 2013-06-03T04:48:48.987 回答
-1

我做了以下事情:

1) 添加了#import "CorePlot-CocoaTouch.h" 2) 将:UIViewController 添加到 .h vc 文件 3) 添加了来自 CPTest 应用程序的完全相同的代码 4) 将 coreplot-cocoatouch 框架添加到我的项目中,将依赖项设置为目标设置,在项目设置中设置标题搜索和其他链接(分别为用户..../framework & -ObjC),添加 QuartzCore 框架,当我编译时我得到:

导入“CorePlot-CocoaTouch.h”没有这样的文件或目录....

我不明白为什么它找不到头文件...

于 2010-02-08T20:17:50.930 回答