4

I'm trying to draw a temperature graph using iso-charts where the x axis data would be set from a server timestamp but the labels would be readable text.

For instance the graph x-axis label would start at Monday 00:00 and end Tuesday 12pm but the LineChartDataSet would be a collection of temperature (y-axis) and timestamps for the x

To display the timestamp I have a custom valueFormatter set as follow (which works great) lineChartView.xAxis.valueFormatter = timestampXAxisFormatter() //converts timestamp to Date string

My question: The LineChartDataSet seems to be indexed based which is causing some trouble: if I have 4 data points such as (9am, 10), (9:15am, 11), (12pm, 15), (1pm, 16) the 4 points are set in the chart at regular intervals (I was expecting 2 points to be on the left side of the graph and then last 2 points on the right side) - Is there a way to have a data set that is based on the x value instead of the index?

I saw ChartData has an init that takes an array of NSObjects but then it converts it to Strings...Thanks in advance for any suggestions you may have!

4

1 回答 1

3

没有好的方法可以解决它,因为您发现 x 轴是基于索引的。

你有两个选择:

  1. 在每个实际 x 值之间插入许多 x 值,例如在 9:00 和 9:15 之间,您手动插入 9:01、9:02、...、9:14,但不要在这些值处添加任何条目,忽略它并继续。如果没有找到条目,ios-charts 将跳过并转到下一个。如果您没有要插入的大量值,这将正常工作。我尝试了 ~1000 个值,性能是可以接受的。

  2. 您创建自己的图表,使用两个 y 轴,一个作为 x 轴,一个作为 y 轴,因此到 0 点的距离是按值计算的。然而,这需要您深入了解 ios-chart 逻辑。如果你成功了,我们非常欢迎你提交 PR。

于 2016-01-02T01:55:58.600 回答