CorePlot:带日期的x轴,仅显示第一个日期标签? [英] CorePlot: x-Axis with dates, only the first date label is showing?

查看:95
本文介绍了CorePlot:带日期的x轴,仅显示第一个日期标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在x轴上带有日期的Core-Plot散点图:

I have a Core-Plot Scatter Plot with dates on the x-Axis:

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;

但x轴上仅显示第一个日期:

But only the first date is displayed on the x-Axis:

使用以下代码创建图形的测试数据:

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

我的x轴出现问题或提供的数据不正确?

Either soemthing is wrong with my x-Axis or the data supplied is not correct?

推荐答案

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

Your x-values are 0.5 units apart while the major tick marks are oneDay (24 * 60 * 60 = 86,400) units apart. 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.

这篇关于CorePlot:带日期的x轴,仅显示第一个日期标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆