I need help in plotting date vs number graph using CorePlot. I have already checked out DatePlot. But my requirement is bit different which is as follows.
I have an array of objects where each object has got a NSDate and a Double number.
For ex:
Array of 5 objects: (NSDate in format yyyy-mm-dd)
- Object1 – 2012-05-01 – 10.34
- Object2 – 2012-05-02 – 10.56
- Object3 – 2012-05-03 – 10.12
- Object4 – 2012-05-04 – 10.78
- Object5 – 2012-05-05 – 10.65
This data comes from a service and would differ every time.
Please advise.
I used a
CPTScatterPlotto display a graph of time series data like yours.You need to create a data source class which will be queried by core plot when it is drawing the graph. My data source object contains an
NSArrayof objects with two attributes:observationDateandobservationValue. The class has to implement theCPTPlotDataSourceprotocol. These are the protocol methods that I implemented:Note that I am converting the date to a double – dates cannot be plotted directly. I implement other methods on the class to return values such as the start and end dates of the time series and the min/max values – these are useful when configuring the PlotSpace of your graph.
Once you have initialised your data source you then assign it to the dataSource property of your CPTScatterPlot:
Have a look at the CPTTestApp in the core plot download for details of configuring your graph and plotspace. If you need any more details please ask. Good luck!