0

Currently I am working on already established application which uses Core plot and in specific its using ScatterPlot to draw a graph. This graph is drawn with values obtained from connected bluetooth device so the graph is dynamically drawn. XY graph with X axis having time value and Y axis having value from BLE device.

Now the requirement is to add an out of range value with a label "OL" in the graph and its not a fixed constant value for the bluetooth device(Its more of a state set in model object that is constructed in BLE layer with junk value obtained for that state and on which we can figure out its a out of range value).

So for e.g., if I get 'OL' value initially then I need to add it on graph above 0 with label "OL". '-OL' below 0 with label "-OL". The values obtained from BLE is continuously added to array and the graph is redrawn using this array.

So behaviour is expected as below: If I get 200 as value in the array and if the array has OL value then OL value has to be plotted above 200 and if the next value from BLE is 300 which will be added to array and since OL is above 200, now OL has to be plotted above 300.

I tried 2-3 different approaches to figure out a solution for this but with no success.

Image of the expected requirement:

Image of the expected requirement

Require someone to help out if its possible to implement this using Core plot.

Eric Skroch
  • 27,381
  • 3
  • 29
  • 36

1 Answers1

0

You'll need a second scatter plot for the red lines. In the main plot, return nil from the datasource for the values that are outside the valid range. This will leave gaps in the line, to be filled in with the other plot.

For the second plot, return nil from every data index, except ones that are out of the valid range. Return the range limit value for those points. You'll also need to return the correct in-range value for the two points on either side of the out-of-range values to connect the line to the main plot line.

Eric Skroch
  • 27,381
  • 3
  • 29
  • 36
  • with 2 different scatter plots we can differentiate values but my question is also into supplying the OL string as label in the "Y" axis as in the image. I created a NSFormatter subclass and override the stringForObject and stringForValue and return OL as many websites specify, but issue i am facing is how to identify whether its a OL value or not in the formatter class. Could you pls provide your inputs on this ASAP. – Shrikanth Ananth Dec 08 '16 at 07:15
  • Use custom y-axis labels (`CPTAxisLabelingPolicyNone`) to display "OL" at the limit values. You probably don't need a custom formatter to do this. Format the numeric values normally and return the "OL" string for the OL values when creating the custom labels. If the OL value changes based on new data, update the tick locations and labels to match the new values and reload the plot data to draw the red segments in the right place based on the new OL value. – Eric Skroch Dec 08 '16 at 12:52
  • Thank you Eric for your response. I am new to Core plot.I need more info w.r.t solution you provided. I tried myself and googled but with no success. "Return the range limit value for those points. You'll also need to return the correct in-range value for the two points on either side of the out-of-range values to connect the line to the main plot line." - Could you pls guide me how to implement this. – Shrikanth Ananth Dec 13 '16 at 05:43
  • For example, if only the point at index 2 is out of range, return the OL value at index 2 and the correct data values at indices 1 and 3. Return `nil` for every other index. – Eric Skroch Dec 13 '16 at 12:49
  • Thank you Eric. A follow up question, I am using shouldUpdateAxisLabels and shouldUpdateMinorAxisLabels to update labels, since the data array is dynamically appended and range keeps changing dynamically as well. It so happens that either all majorLocations labelled will be displayed in graph or minorLocations labels are displayed. So, is it possible to set labels like if a OL label is a major location and -OL label is a minor location using these methods or otherwise. – Shrikanth Ananth Dec 29 '16 at 08:49
  • @ShrikanthAnanth I don't understand your followup question. Please ask a new question on StackOverflow. It will give you more room to provide details about the question. – Eric Skroch Dec 29 '16 at 13:24