【发布时间】:2014-06-17 20:27:43
【问题描述】:
我正在尝试使用 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];
【问题讨论】:
标签: objective-c cocoa plot core-plot