作为一名Java和Android初学者,我发现大多数文档仍然很难理解,但我认为这可以通过知道自己在做什么的人轻松解决:
我正在使用Android View的Graph View来构建一个简单的图形。 到目前为止这是有效的,但我想要实现的是通过按下按钮设置我的数据数组的最后一个变量+1或-1 。
所以我在应用程序启动时生成一个固定的数据集:
private LineGraphSeries<DataPoint> mSeries1 = new LineGraphSeries<DataPoint>(new DataPoint[] { new DataPoint(1, 1), new DataPoint(2, 5), new DataPoint(3, 3), new DataPoint(4, 2), new DataPoint(5, mCigCount) });其中mCigCount是我所说的变量。 它通过按钮按下获得+1或-1,这确实可以正常工作。
问题是,如何更新我的Graph,以便在按下按钮后正确呈现mCigCount的新值?
本教程以复杂的方式进行,每秒都有一些随机数和更新,这对我来说仍然太混乱了。 它还提到了我无法正确使用的方法resetData和appendData ,因为我不明白我必须把它放在(...)中 :
mSeries1.resetData(...); mSeries1.appendData(...);如何处理我的上一个数据点并更新其中的mCigCount?
As a Java & Android beginner I find it still hard to understand most documentations, but I think this can be solved easily by someone who knows what they are doing:
I'm using Graph View for Android Studio to build a simple graph. This is working good so far, but what I want to achieve is to set the last variable of my data array +1 or -1 by the push of a button.
So I generate a fixed dataset when the app starts:
private LineGraphSeries<DataPoint> mSeries1 = new LineGraphSeries<DataPoint>(new DataPoint[] { new DataPoint(1, 1), new DataPoint(2, 5), new DataPoint(3, 3), new DataPoint(4, 2), new DataPoint(5, mCigCount) });where mCigCount is the variable I spoke of. It gets +1 or -1 by a button push, which does work already fine.
The problem is, how do I update my Graph so that the new value for mCigCount will be rendered correctly after the button push?
This tutorial does it in a complicated way with some random numbers and updates every second, which is still way too confusing for me. It also mentions the methods resetData and appendData on which I fail to use correctly, because I dont understand what I have to put inside the (...):
mSeries1.resetData(...); mSeries1.appendData(...);How can I adress my last data point and update the mCigCount in it?
最满意答案
好的,我找到了一个解决方法,虽然这不是我眼中的好解决方案,所以请随时用resetData和appendData来纠正我!
我基本上擦除了系列中的每个数据,然后将其全新写入。 此方法的问题是,每次更新时视图都会闪烁,因为它会被删除并重新创建:
GraphView graph = (GraphView) findViewById(R.id.graph); graph.removeAllSeries(); LineGraphSeries<DataPoint> mSeries1 = new LineGraphSeries<DataPoint>(new DataPoint[] { new DataPoint(1, 1), new DataPoint(2, 5), new DataPoint(3, 3), new DataPoint(4, 2), new DataPoint(5, mCigCount) }); LineGraphSeries<DataPoint> series = mSeries1; graph.addSeries(series);Okay I found a workaround for me, although this is not a good solution in my eyes, so please feel free to correct me with resetData and appendData!
I basically erase every Data in my series and then write it completely new. Problem with this method is, that the view is flickering at each update because it gets deleted and recreated:
GraphView graph = (GraphView) findViewById(R.id.graph); graph.removeAllSeries(); LineGraphSeries<DataPoint> mSeries1 = new LineGraphSeries<DataPoint>(new DataPoint[] { new DataPoint(1, 1), new DataPoint(2, 5), new DataPoint(3, 3), new DataPoint(4, 2), new DataPoint(5, mCigCount) }); LineGraphSeries<DataPoint> series = mSeries1; graph.addSeries(series);更多推荐
发布评论