Search code examples
iosobjective-ccore-plot

CPTScatterPlot connect point with skip some data point


For example, from 09:00am to 09:05:am
Ideally, I got 6 points from server for my plot.

- (NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
   return 6;
}

dataSource

Index Time  Price    

0     09:00 84.2
1     09:01 84.5
2     09:02 84.1
3     09:03 84.0
4     09:04 84.1
5     09:05 84.0

But, In fact, Server will response data source like this

Index Time  Price    
0     09:00 84.2
1     09:01 84.5
2     09:02 nil
3     09:03 nil
4     09:04 84.1
5     09:05 84.0

I return 6 for numberOfRecordsForPlot
And nil for numberForPlot index 2 and 3
I will get plot like this enter image description here My question is if index 2 and index 3 no data
How do I connect index 1 to index 4 with a straight line
i.e. connect (1, 84.5) to (4, 84.1) using a straight line


Solution

  • Since you only have four data points to plot, -numberOfRecordsForPlot: should return 4. The datasource should also skip over the nil values:

    Index Time  Price    
    0     09:00 84.2
    1     09:01 84.5
    2     09:04 84.1
    3     09:05 84.0