核心图和NSDate(iPhone) [英] core-plot and NSDate (iPhone)

查看:132
本文介绍了核心图和NSDate(iPhone)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一个线图,其中x轴被定义为两个日期之间的天数,y轴是每个天数不同的值。

I wish to plot a line graph where the x-axis is defined as a number of days between two dates and the y-axis is a value that varies on each of the days.

我可以将y值绘制为NSNumber,但我不知道如何在x轴上设置范围和标记。我看过核心图分布的examples目录中的日期示例,但是发现它有点混乱。

I can plot the y values as an NSNumber but I have no idea how to set the ranges and the markup on the x-axis. I have looked at the date example in the "examples" directory of the core-plot distribution but have found it a little confusing.

有人知道一个教程,还是代码示例,这可能在这方面与我有任何关系?

Does anyone know of a tutorial, or code sample, which might asist me in this regard?

提前谢谢。

推荐答案

您需要注意以下两个主要概念:如何格式化日期以及如何将日期转换为轴范围和数据值的数字。

There are two main concepts you need to be aware of: how to format the dates and how to convert the dates into numbers for the axis ranges and data values.

Core Plot提供了一个负责格式化的 CPTimeFormatter 类。您提供一个 NSDateFormatter 设置为您要使用的任何格式和参考日期来定义数字比例的原点。将轴上的 labelFormatter 属性设置为您初始化的 CPTimeFormatter ,并将数据数据转换为日期和应用所需的格式。

Core Plot provides a CPTimeFormatter class that takes care of the formatting. You provide an NSDateFormatter set to whatever format you want to use and a reference date to define the origin of the numeric scale. Set the labelFormatter property on the axis to your initialized CPTimeFormatter and it will take care of converting the numeric data to dates and applying the desired format.

计算数值的关键是您需要在几秒钟内找到参考日期和感兴趣的日期值之间的差异。这就是为什么样本程序定义了oneDay = 24 * 60 * 60。

The key to calculating the numeric values is that you need to find the difference between your reference date and the date value of interest in seconds. That's why the sample program defined oneDay = 24 * 60 * 60.

24小时/天* 60分钟/小时* 60秒/分钟= 86400秒/天。

24 hrs/day * 60 min/hr * 60 sec/min = 86400 sec/day.

这篇关于核心图和NSDate(iPhone)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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