简体   繁体   English

CorePlot:带日期的x轴,仅显示第一个日期标签?

[英]CorePlot: x-Axis with dates, only the first date label is showing?

I have a Core-Plot Scatter Plot with dates on the x-Axis: 我在x轴上有一个核心图散点图,其中有日期:

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;

But only the first date is displayed on the x-Axis: 但是x轴上仅显示第一个日期:

在此处输入图片说明

The test data for the graphs is created with this code: 使用以下代码创建图形的测试数据:

-(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;
}

Either soemthing is wrong with my x-Axis or the data supplied is not correct? 我的x轴出现问题或提供的数据不正确?

Your x-values are 0.5 units apart while the major tick marks are oneDay (24 * 60 * 60 = 86,400) units apart. 您的x值相隔0.5个单位,而主要刻度线oneDay (24 * 60 * 60 = 86,400)个单位。 If the x-values are supposed to be dates, multiply the current values by oneDay and expand the xRange of the plot space to cover the larger range of values. 如果x值应该是日期,则将当前值乘以oneDay并扩展绘图空间的xRange以覆盖更大范围的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM