Core-Plot 如何打包数据
我想知道我需要如何准备数据以便为核心图做好准备。
- 每年一行
- x 轴上的 dayOfYear
- y 轴上的值
我的 x 轴有 366 个点(一年中的每一天)。目前我有一本看起来像这样的字典,
2009 (year) = {
151 (dayofyear) = 5 (value);
192 = 25;
206 = 5;
234 = 20;
235 = 20;
255 = 20;
262 = 10;
276 = 10;
290 = 10;
298 = 7;
310 = 1;
338 = 3;
354 = 5;
362 = 5;
};
2010 = {
114 = 7;
119 = 3;
144 = 7;
17 = 5;
187 = 10;
198 = 7;
205 = 10;
212 = 10;
213 = 20;
215 = 5;
247 = 10;
248 = 10;
256 = 10;
262 = 7;
264 = 10;
277 = 10;
282 = 3;
284 = 7;
47 = 5;
75 = 7;
99 = 7;
};
2011 = {
260 = 10;
};
我认为核心图需要一个数组,不是吗?您将如何打包才能最有效?
I was wondering how I need to prepare the data so it is ready for core-plot.
- one line per year
- dayOfYear in the x-axis
- value on the y-axis
My x-axis has 366 points (Each day of the year). At the moment I have a dictionary that looks like this
2009 (year) = {
151 (dayofyear) = 5 (value);
192 = 25;
206 = 5;
234 = 20;
235 = 20;
255 = 20;
262 = 10;
276 = 10;
290 = 10;
298 = 7;
310 = 1;
338 = 3;
354 = 5;
362 = 5;
};
2010 = {
114 = 7;
119 = 3;
144 = 7;
17 = 5;
187 = 10;
198 = 7;
205 = 10;
212 = 10;
213 = 20;
215 = 5;
247 = 10;
248 = 10;
256 = 10;
262 = 7;
264 = 10;
277 = 10;
282 = 3;
284 = 7;
47 = 5;
75 = 7;
99 = 7;
};
2011 = {
260 = 10;
};
I think core-plot needs an array doesn't it? How would you pack this to be the most efficient?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
数据结构的选择完全取决于您。您已经将数据存储在字典中,因此请保留它。在数据源中实现以下方法:
假设您每年都有一个单独的绘图,请使用
plot
参数从数据字典中选择适当的年份字典。使用fieldEnum
参数来确定绘图是否要求 x 或 y 值,并使用index
参数来决定返回列表中的哪个值。例如(假设字典中的所有值都存储为 NSNumber 对象并且您使用散点图):
The choice of data structure is completely up to you. You already have the data in a dictionary, so keep that. Implement the following method in your datasource:
Assuming you have a separate plot for each year, use the
plot
parameter to select the appropriate year dictionary from the data dictionary. Use thefieldEnum
parameter to determine whether the plot is asking for the x or y value and theindex
parameter to decide which value in the list to return.For instance (assuming all values in the dictionaries are stored as NSNumber objects and you're using a scatter plot):
我实际上已经将结构更改为这样。
以年份为键的字典,每个点都有一个包含年份和值的数组。
这样实施就非常容易了
I have actually changed the structure to this.
A dictionary with the year as the key and an array for each point containing the dayofyear and the value.
That way the implementation was very easy