CorePlot:x轴与date,只有第一个date标签显示?

我有一个核心情节散点图在X轴上的date:

NSDateComponents *dateComponents = [[NSDateComponents alloc] init]; [dateComponents setMonth:10]; [dateComponents setDay:29]; [dateComponents setYear:2009]; [dateComponents setHour:12]; [dateComponents setMinute:0]; [dateComponents setSecond:0]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *refDate = [gregorian dateFromComponents:dateComponents]; NSTimeInterval oneDay = 24 * 60 * 60; CPTXYAxis *x = axisSet.xAxis; x.majorIntervalLength = CPTDecimalFromFloat(oneDay); x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"2"); x.minorTicksPerInterval = 0; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.dateStyle = kCFDateFormatterShortStyle; CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter]; timeFormatter.referenceDate = refDate; x.labelFormatter = timeFormatter; x.labelRotation = M_PI / 4; 

但是只有第一个date显示在X轴上:

在这里输入图像说明

这个图的testing数据是用这个代码创build的:

 -(NSMutableArray *)testData{ NSMutableArray *testArray = [NSMutableArray arrayWithCapacity:100]; [testArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:0.0f], @"x", [NSNumber numberWithFloat:19.0f], @"y", nil]]; [testArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:0.5f], @"x", [NSNumber numberWithFloat:20.0f], @"y", nil]]; [testArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:1.0f], @"x", [NSNumber numberWithFloat:18.5f], @"y", nil]]; [testArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:1.5f], @"x", [NSNumber numberWithFloat:19.5f], @"y", nil]]; [testArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:2.0f], @"x", [NSNumber numberWithFloat:21.5f], @"y", nil]]; [testArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:2.5f], @"x", [NSNumber numberWithFloat:20.5f], @"y", nil]]; [testArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:3.0f], @"x", [NSNumber numberWithFloat:20.0f], @"y", nil]]; [testArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:3.5f], @"x", [NSNumber numberWithFloat:20.5f], @"y", nil]]; [testArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:4.0f], @"x", [NSNumber numberWithFloat:24.0f], @"y", nil]]; [testArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:4.5f], @"x", [NSNumber numberWithFloat:23.5f], @"y", nil]]; return testArray; } 

我的X轴或者提供的数据不正确?

您的x值相差0.5个单位,而主要的刻度线是oneDay (24 * 60 * 60 = 86,400)。 如果x值应该是date,则将当前值乘以oneDay然后展开绘图空间的xRange以覆盖更大范围的值。

Interesting Posts