Core plot-Add OutOfRange to draw graph that changes dynamically with label “OL”

梦想的初衷 提交于 2020-01-06 15:59:11

问题


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:

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


回答1:


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.



来源:https://stackoverflow.com/questions/40582944/core-plot-add-outofrange-to-draw-graph-that-changes-dynamically-with-label-ol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!