I need to dinamically update a scatterplot graph with realtime data. The data are speed (Y axis) depending on time (X axis).
As soon as I have new speed data, I add data to the datasource array then call [graph reloadData] to update the graph. And this is good, but how to automatically make the graph scrolling on x axis in order that the new data is always on screen?
Thanks.
Solution found: need to update this property ((CPTXYPlotSpace *)graph.defaultPlotSpace).xRange
Related
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.
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.
I'm trying to plot a ECG on an IOS application using Core Plot library like this video .I have tried to plot ECG like in the video in my IOS APP.I got the following result.
In general ECG graph should be plotted from the left end of the graph(Lead 1 in Screen shot) after a specific time interval.When i'm plotting ECG in my APP after the specified time interval,Each graph gets plotted on top of the previous graph.
How can we solve this?
You can implement this similar to the "Real Time Plot" demo in the Plot Gallery example app, although your application is a little simpler since you don't need to update the plot space after each frame of new data. You can leave a gap in the plot line by inserting a data point with a NSNull or NAN value between the points on either side of the break.
The plot must redraw after every change to the plot data, so you need to balance the size (pixel dimensions) of the plot and the number of data points with the desired update rate. Note that ranges are specified with a start location and the length of the range. To add a new data point and move the blank space over one spot, reload a range starting at the arrayIndex and length of two (2). Increment the arrayIndex for each new point and wrap around to index zero (0) when you get to the end.
As part of my app, the user can select a different location which has different data to be graphed. The initial location's data plots fine through ViewDidLoad, when the location is changed, under viewDidAppear, [graph reloadData] is called which works fine for the plots but the X & Y axis's are all wrong due to different values. is there an easy way to redraw the axis's? otherwise i might have to much around with separate methods for parts of the graph creation?
Update the xRange and/or yRange of the plot space at the same time you call -reloadData to update the plots. You can also update any of the labeling properties if needed.
I would like to draw the graph for every second like the AccelerometerGraph example by apple . But only one change in drawing is I have to draw the graph based on x and y axis . I have tried using the Coreplot . It is showing the graph once we store the values in the array statically . But I have to draw dynamically
inside didAccelerate delegate you can update your array and call [graph reloadData]; to update your coreplot graph. or if you want it to draw after every 10 seconds then call reloadData after 10 seconds delay.
I want to use core-plot for drawing line graph dynamically. data won't come at a time, we will be receiving point by point dynamically.
Is it possible to draw the chart dynamically using core-plot i.e drawing point by point as on when we receive the (x,y) point?
Please help me, Thanks.
Yes, you can do this reasonably easily. For each received data point, append it to an array of values to display. As these data points come in, call -reloadData on the Core Plot graph (or just the particular plot) to redraw the graph, passing in the array you just added a value to in response to the -numbersForPlot:field:recordIndexRange: delegate method.
If you need to adjust the plot range to track your data points (for a moving ticker), recalculate the new CPPlotRange for the X axis and set the plot space's xRange property to that.
Use the CPTestApp-iPhone, AAPLot, or StockPlot examples as templates for how to set up the line chart overall, and modify from that starting point.
I do something similar to this on the Mac in a scientific application:
(source: sunsetlakesoftware.com)
Sounds like you could make use of a demo project I put together and wrote about here (not core plot related though).
It draws a EKG graph but should easily be modified to use another input than the repeated "heart beat"...See line 320 in EAGLView.m where the indata is entered into the array.