2014-06-17 75 views
0

我想繪製使用CorePlot的1圖上的2行。現在我正在繪製相同的數據兩次,我不知道如何選擇其他數據源。無法區分繪圖的數據,CorePlot

任何幫助,將不勝感激。

代碼:

圖形視圖代碼.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]; 

回答

0

你就擁有了一切正確的包括測試情節identifierfieldEnum。一旦確定哪個圖是要求數據的,請使用它來選擇正確的數據數組,而不是從兩個圖中獲取來自self.graphData的計數和數據點。