views:

217

answers:

1

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.

+1  A: 

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.

Eric Skroch