我已升级到最新版本的Coreplot(1.2)并遇到了问题。
我的图表里面有两个图。条形图和散点图。散点图是连接条形的线条表示。一切都在版本1.1中运行良好,但当我切换1.2时,Scatter图似乎放错了位置。这是从一点开始的开始。这是图像:
那些符号符号和整个散点图与条形图同步(即符号位于freen条的中间,而不是在它之外,符号在网格线上)应该如此。从numberForPlot
返回的点数值相同。
以下是我的numberForPlot
方法,以防万一:
- (NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx
{
if ([plot.identifier isEqual:kBarPlot] )
{
if (fieldEnum == CPTBarPlotFieldBarLocation)
return [NSNumber numberWithInt:[self.intervalStringArray indexOfObject:[allKeys objectAtIndex:idx]]];
NSArray *activitiesForDate = [activitiesByDate valueForKey:[allKeys objectAtIndex:idx]];
double activityAmount = 0.0;
if (activitiesForDate)
{
//compute value
}
DebugLog(@"Barplot returning Y= %f forindex = %d", activityAmount, idx);
return [NSNumber numberWithDouble:activityAmount];
}
if ([plot.identifier isEqual:kScatterPlot])
{
NSString *currentDate = [[self activityDatesAsString] objectAtIndex:idx];
if (fieldEnum == CPTScatterPlotFieldX)
{
int currentIndex = [self.intervalStringArray indexOfObject:currentDate];
return [NSNumber numberWithInt:currentIndex];
}
NSArray *activitiesForDate = [self activitiesForDate:[self.dateFormatter dateFromString:currentDate]];
float netActivity = 0.0;
//compute netActvity
DebugLog(@"SCATTERPLOT returning %@ for index %d", [NSNumber numberWithFloat:netActivity], idx);
return [NSNumber numberWithFloat:netActivity];
}
return nil;
}
最后,日志输出是;
SCATTERPLOT returning -8 for index 0
SCATTERPLOT returning -4 for index 1
Barplot returning Y= -8.000000 for index = 0
Barplot returning Y= -4.000000 for index = 1
编辑:虽然我已经差不多完成了这里的代码发布,但问题仍然存在,即使散点图在图表中是独自存在的。我发现了这个问题,但我不知道它是否正常或是否是一个错误。问题在于CPTMutableShadow
:
CPTScatterPlot *netActivityPlot = [[[CPTScatterPlot alloc] init] autorelease];
netActivityPlot.identifier = kNetActivityPlot;
netActivityPlot.title = @"Net Activity";
CPTMutableLineStyle *lineStyle = [[netActivityPlot.dataLineStyle mutableCopy] autorelease];
lineStyle.lineWidth = 2.0;
lineStyle.lineColor = _cptNetActivityLineColor;
netActivityPlot.dataLineStyle = lineStyle;
netActivityPlot.dataSource = self;
CPTMutableShadow *shadow = [CPTMutableShadow shadow];
shadow.shadowColor = [CPTColor lightGrayColor];
shadow.shadowOffset = CGSizeMake(2.0, -2.0);
shadow.shadowBlurRadius = 4.0f;
netActivityPlot.shadow = shadow;
[activityGraph addPlot:netActivityPlot];
netActivityPlot.plotSpace = (CPTXYPlotSpace *)activityGraph.defaultPlotSpace;
当我移除阴影时,情节适合于线条。