为什么我无法控制 Core-Plot 日期轴刻度?

发布于 2024-09-16 19:13:38 字数 1571 浏览 6 评论 0原文

我有一个 Core-Plot 散点图,看起来效果很好。 x 轴显示日期/时间,y 轴显示 0-500 之间的值。我按如下方式设置 x 轴:

    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:
                        CPDecimalFromFloat(maxTime - 2*60*60*24) 
                         length:CPDecimalFromFloat(2.5*60*60*24)];
    plotSpace.globalXRange = [CPPlotRange plotRangeWithLocation:
                        CPDecimalFromFloat(minTime - 1.5*60*60*24) 
                         length:CPDecimalFromFloat(maxTime - minTime + 2*60*60*24)];

    x.majorIntervalLength = CPDecimalFromFloat(12*60*60);
    x.minorTicksPerInterval = 0;
    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:@"M/d H:mm a"];
    CPTimeFormatter *timeFormatter = [[[CPTimeFormatter alloc]
                initWithDateFormatter:dateFormatter] autorelease];
    timeFormatter.referenceDate = [NSDate
                dateWithTimeIntervalSinceReferenceDate:0];
    x.labelFormatter = timeFormatter;

我的 x 轴点绘制如下:

-(NSNumber *)numberForPlot:(CPPlot *)plot 
                     field:(NSUInteger)fieldEnum 
               recordIndex:(NSUInteger)index 
{
    if(fieldEnum == CPScatterPlotFieldX) { 
        return [NSNumber numberWithDouble:[[(Entry *)
            [datapoints objectAtIndex:index] datetime]
            timeIntervalSinceReferenceDate]]; 
    }

据我所知,所有内容都被准确绘制。但是,由于某种原因,滴答声发生在上午 5 点和下午 5 点,而不是我希望的中午和午夜。

我已经尝试了一切 - 更改 xRange 和 globalXRange 位置和长度、更改我的数据集等。但每次标签都会在上午 5 点和下午 5 点重新出现。你能帮忙吗?谢谢!

I have a Core-Plot scatter plot that seems to be working great. The x axis shows date/time, the y axis a value from 0-500. I set up the x axis as follows:

    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:
                        CPDecimalFromFloat(maxTime - 2*60*60*24) 
                         length:CPDecimalFromFloat(2.5*60*60*24)];
    plotSpace.globalXRange = [CPPlotRange plotRangeWithLocation:
                        CPDecimalFromFloat(minTime - 1.5*60*60*24) 
                         length:CPDecimalFromFloat(maxTime - minTime + 2*60*60*24)];

    x.majorIntervalLength = CPDecimalFromFloat(12*60*60);
    x.minorTicksPerInterval = 0;
    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:@"M/d H:mm a"];
    CPTimeFormatter *timeFormatter = [[[CPTimeFormatter alloc]
                initWithDateFormatter:dateFormatter] autorelease];
    timeFormatter.referenceDate = [NSDate
                dateWithTimeIntervalSinceReferenceDate:0];
    x.labelFormatter = timeFormatter;

My x-axis points are plotted as follows:

-(NSNumber *)numberForPlot:(CPPlot *)plot 
                     field:(NSUInteger)fieldEnum 
               recordIndex:(NSUInteger)index 
{
    if(fieldEnum == CPScatterPlotFieldX) { 
        return [NSNumber numberWithDouble:[[(Entry *)
            [datapoints objectAtIndex:index] datetime]
            timeIntervalSinceReferenceDate]]; 
    }

As far as I can tell, everything is being plotted accurately. BUT, for some reason, the ticks occur at 5 AM and 5 PM, rather than noon and midnight as I would prefer.

I've tried everything -- changing the xRange and globalXRange location and length, altering my dataset, etc. But every time the labels reappear at 5 AM and 5 PM. Can you help? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿忘初心 2024-09-23 19:13:38

5小时听起来像是时区问题。尝试将 dateFormatter 上的 timeZone 属性设置为 [NSDateFormatter timeZoneForSecondsFromGMT:0]

5 hours sounds like a time zone problem. Try setting the timeZone property on your dateFormatter to [NSDateFormatter timeZoneForSecondsFromGMT:0].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文