无法区分图表的数据,CorePlot

时间:2014-06-17 20:27:44

标签: objective-c cocoa plot core-plot

我正在尝试使用CorePlot在1个图表上绘制2条线。现在我正在绘制两次相同的数据,我不知道如何选择其他数据源。

任何帮助都将不胜感激。

代码:

图表视图代码.m:

    CPTScatterPlot *limitplot = [[CPTScatterPlot alloc] init];
    limitplot.dataSource = self;
    limitplot.identifier = @"limplot";
    limitplot.dataLineStyle = lineStylelimit;
    limitplot.plotSymbol = plotSymbollimit;
    [self.graph addPlot:limitplot];

    CPTScatterPlot *calplot = [[CPTScatterPlot alloc] init];
    calplot.dataSource = self;
    calplot.identifier = @"plot";
    calplot.dataLineStyle = lineStylecalc;
    calplot.plotSymbol = plotSymbolcalc;
    [self.graph addPlot:calplot];
}

// Delegate method that returns the number of points on the plot
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
    if ( [plot.identifier isEqual:@"limplot"] )
    {
        return [self.graphData count];
    }
    else if ( [plot.identifier isEqual:@"plot"] )
    {
        return [self.graphData count];
    }

    return 0;
}

// Delegate method that returns a single X or Y value for a given plot.
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
    if ( [plot.identifier isEqual:@"limplot"] )
    {
        NSValue *value = [self.graphData objectAtIndex:index];
        CGPoint point = [value CGPointValue];

        // FieldEnum determines if we return an X or Y value.
        if ( fieldEnum == CPTScatterPlotFieldX )
        {
            return [NSNumber numberWithFloat:point.x];
        }
        else    // Y-Axis
        {
            return [NSNumber numberWithFloat:point.y];
        }
    } else if ( [plot.identifier isEqual:@"plot"] )
    {
        NSValue *value = [self.graphData objectAtIndex:index];
        CGPoint point = [value CGPointValue];

        // FieldEnum determines if we return an X or Y value.
        if ( fieldEnum == CPTScatterPlotFieldX )
        {
            return [NSNumber numberWithFloat:point.x];
        }
        else    // Y-Axis
        {
            return [NSNumber numberWithFloat:point.y];
        }
    }


    return [NSNumber numberWithFloat:0];
}

数据.m:

NSMutableArray *limitdata = [NSMutableArray array];
[limitdata addObject:[NSValue valueWithCGPoint:CGPointMake(5477, 5400)]];
[limitdata addObject:[NSValue valueWithCGPoint:CGPointMake(5292, 5400)]];
[limitdata addObject:[NSValue valueWithCGPoint:CGPointMake(5053, 6425)]];
[limitdata addObject:[NSValue valueWithCGPoint:CGPointMake(5029, 7154)]];
[limitdata addObject:[NSValue valueWithCGPoint:CGPointMake(5138, 8300)]];
[limitdata addObject:[NSValue valueWithCGPoint:CGPointMake(5503, 8300)]];
[limitdata addObject:[NSValue valueWithCGPoint:CGPointMake(5570, 7100)]];
[limitdata addObject:[NSValue valueWithCGPoint:CGPointMake(5477, 5400)]];

self.lewis = [[TUTSimpleScatterPlot alloc] initWithHostingView:_graphHostingView andData:limitdata];
[self.lewis initialisePlot];

double cofullMass = [coTOMass doubleValue];
double cofullStation = [coTOstation doubleValue];
double coeeMass = [coEEmass doubleValue];
double coeeStation = [coEEstation doubleValue];
double cossMass = [coSSmass doubleValue];
double cossStation = [coSSstation doubleValue];
double codryMass = [coZmass doubleValue];
double codryStation = [coZstation doubleValue];


NSMutableArray *caldata = [NSMutableArray array];
[caldata addObject:[NSValue valueWithCGPoint:CGPointMake(cofullStation, cofullMass)]];
[caldata addObject:[NSValue valueWithCGPoint:CGPointMake(coeeStation, coeeMass)]];
[caldata addObject:[NSValue valueWithCGPoint:CGPointMake(cossStation, cossMass)]];
[caldata addObject:[NSValue valueWithCGPoint:CGPointMake(codryStation, codryMass)]];



self.lewis = [[TUTSimpleScatterPlot alloc] initWithHostingView:_graphHostingView andData:caldata];
[self.lewis initialisePlot];

1 个答案:

答案 0 :(得分:0)

您已经掌握了一切正确的内容,包括测试情节identifierfieldEnum。确定哪个绘图要求数据后,使用它来选择正确的数据数组,而不是从self.graphData获取两个绘图的计数和数据点。