代码之家  ›  专栏  ›  技术社区  ›  Paul Peelen

核心图问题

  •  2
  • Paul Peelen  · 技术社区  · 15 年前

    我从核心情节开始,遇到了一些问题。我按照本页的教程操作: http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application

    并完成本页的说明: http://code.google.com/p/core-plot/wiki/UsingCorePlotInApplications (例如-所有负载)。

    但我仍然有一些问题,我得到以下错误:

    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];
    }
    
    5 回复  |  直到 12 年前
        1
  •  10
  •   Brad Larson    15 年前

    您所指的示例已过时,不再与核心绘图框架的当前API匹配。我建议从框架附带的示例应用程序开始(在examples目录中),因为我们一直在更新这些应用程序以匹配任何API更改。

    例如 axisLabelOffset 已重命名为 labelOffset , defaultPlotSymbol 不再存在(您设置 plotSymbol 属性),绘图空间不再具有 bounds 属性,您不再需要使用 -initWithFrame: 对于cpplot实例。

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

        2
  •  3
  •   John Stallings    15 年前

    由于MajorIntervalLength需要 NSDecimal 你要退回一个 NSDecimalNumber .查看这是否适用于这些错误:

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

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

        3
  •  1
  •   TriNitroToluene    15 年前
    set the header search and other link (Users..../framework & -ObjC respectively) 
    

    我想你是在提供绝对路径。如果您浏览coreplay文档,您会发现它们已经清楚地提到“您应该在header search path字段中给出相对路径”。

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

        4
  •  0
  •   Venkateswarlu.NP    12 年前

    通过终端命令“mdfind”获取核心图的完整路径,如下所示。

    在终端类型中,mdfind-name coreplay

    将获取完整路径名。

    采用完整路径并插入邮件头搜索路径

    和上面一样…将-objc添加到“othetr链接器标志”中,并将Quartz框架工作添加到“链接二进制与库”中。

    它将起作用:

        5
  •  -1
  •   mars    15 年前

    我做了以下工作:

    1)增加导入“coreplot cocoatouch.h” 2)将:uiviewcontroller添加到.h vc文件中 3)从cptest app添加了完全相同的代码 4)在我的项目中添加了coreplot cocoatouch框架,在目标设置中设置了依赖关系,在项目设置中设置了header search和其他链接(分别是users../framework&-objc),添加了quartzcore框架,编译时得到:

    导入“coreplot cocoatouch.h”没有这样的文件或目录….

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