为什么我无法控制 Core-Plot 日期轴刻度?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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]
.