核心图和 NSDate (iPhone)

发布于 2024-09-04 22:43:17 字数 192 浏览 1 评论 0原文

我希望绘制一个折线图,其中 x 轴定义为两个日期之间的天数,y 轴是每天变化的值。

我可以将 y 值绘制为 NSNumber,但我不知道如何在 x 轴上设置范围和标记。我查看了 core-plot 发行版的“examples”目录中的日期示例,但发现它有点令人困惑。

有谁知道教程或代码示例可以在这方面帮助我?

先感谢您。

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.

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?

Thank you in advance.

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

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

发布评论

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

评论(1

栖迟 2024-09-11 22:43:17

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

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

计算数值的关键是您需要找到参考日期和感兴趣的日期值之间的差异(以秒为单位)。这就是示例程序定义 oneDay = 24 * 60 * 60 的原因。24

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

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 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.

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 hrs/day * 60 min/hr * 60 sec/min = 86400 sec/day.

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