ios 使用核心图在 iPhone 上实时绘图?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2399836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
real time plotting on iPhone using core plot?
提问by Appbrain
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.
我想使用 core-plot 动态绘制折线图。数据不会一次出现,我们将逐点动态接收。
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?
是否可以使用 core-plot 动态绘制图表,即在我们收到 (x,y) 点时逐点绘制?
Please help me, Thanks.
请帮帮我,谢谢。
采纳答案by Brad Larson
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.
是的,您可以相当轻松地做到这一点。对于每个接收到的数据点,将其附加到要显示的值数组。当这些数据点进来时,调用-reloadData
Core Plot 图(或只是特定图)来重绘该图,传入您刚刚添加值的数组以响应-numbersForPlot:field:recordIndexRange:
委托方法。
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.
如果您需要调整绘图范围以跟踪您的数据点(对于移动的股票代码),请重新计算 X 轴的新 CPPlotRange 并将绘图空间的xRange
属性设置为该值。
Use the CPTestApp-iPhone, AAPLot, or StockPlotexamples as templates for how to set up the line chart overall, and modify from that starting point.
使用CPTestApp-iPhone、AAPLot或StockPlot示例作为如何设置折线图整体的模板,并从该起点进行修改。
I do something similar to this on the Mac in a scientific application:
(source: sunsetlakesoftware.com)
我在 Mac 上的一个科学应用程序中做了类似的事情:(
来源:sunsetlakesoftware.com)
回答by epatel
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 EKGgraph but should easily be modified to use another input than the repeated "heart beat"...See line 320 in EAGLView.mwhere the indata is entered into the array.
它绘制了一个心电图图,但应该很容易修改以使用另一个输入而不是重复的“心跳”......请参阅EAGLView.m中的第320 行,其中 indata 被输入到数组中。