Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 了解numberForPlot:和numberOfRecordsForPlot:核心图_Ios_Objective C_Graph_Core Plot - Fatal编程技术网

Ios 了解numberForPlot:和numberOfRecordsForPlot:核心图

Ios 了解numberForPlot:和numberOfRecordsForPlot:核心图,ios,objective-c,graph,core-plot,Ios,Objective C,Graph,Core Plot,我正在实现一个条形图,在理解这两种方法时遇到问题numberForPlot:field:recordIndex:和numberOfRecordsForPlot 我现在有 -(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot { return 4; } -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger

我正在实现一个条形图,在理解这两种方法时遇到问题
numberForPlot:field:recordIndex:
numberOfRecordsForPlot

我现在有

-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
    return 4;
}

-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx {
    switch (idx) {
        case 0:
            return @1;
            break;
        case 1:
            return @2;
            break;
        case 2:
            return @3;
            break;
        case 3:
            return @4;
            break;
        default:
            return @0;
            break;
    }
}
这将生成一个如预期的图形。当我把
@4
改为
@5
时,它会显示最后一个条,旁边有一个空白条。如果我根据
numberOfRecordsForPlot
为4个条目中的每一个绘制x和y位置,这是有意义的,但是当我将信息记录在
numberForPlot
中时,字段枚举只有0和1


我已经看过文档和示例,对我来说并不清楚。有人能解释一下吗?

主要问题是该委托方法的
fieldEnum
没有按照您的想法执行。它的值为
CPTBarPlotFieldBarLocation
(x轴位置)或
CPTBarPlotFieldBarTip
(条形高度),因此这些应该是switch语句中使用的情况。
idx
指的是特定的条形图

在这里,我将条形图的高度放在名为
plotData
的数据源对象的属性中

self.plotData = @[@(1), @(2), @(3), @(4)];
然后可以像这样实现委托方法

-(NSNumber*) numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx {

    switch ( fieldEnum ) {
        case CPTBarPlotFieldBarLocation:
            return @(idx);
            break;

        case CPTBarPlotFieldBarTip:
            return [plotData objectAtIndex:idx];
            break;

        default:
            break;
    }

    return nil;
}