GraphView不刷新 [英] GraphView not refreshing
问题描述
我有一个问题,GraphView不刷新..意思是它改变Y值来适应新的数据,但不绘制它,只是停留在提供的第一个数据,继承人的代码:
public class MainActivity extends Activity
{
double data = 1;
double xgraph = 5;
GraphViewSeries sensorSeries;
GraphView graphView;
...
@Override
public void onCreate(Bundle savedInstanceState)
{
...
sensorSeries =新的GraphViewSeries(新的GraphViewData [] {
新的GraphViewData(1,2.0d)
,新的GraphViewData(2,1.5d)
,新的GraphViewData(3,2.5d)
,新的GraphViewData(4,1.0d)
});
graphView = new LineGraphView(this,TEST);
graphView.addSeries(sensorSeries);
LinearLayout layout =(LinearLayout)findViewById(R.id.graph2);
graphView.setViewPort(0,20);
layout.addView(graphView);
refreshButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
sensorSeries.appendData(new GraphViewData( xgraph,data),false);
graphView.redrawAll();
myLabel.setText(+ data ++ xgraph);
xgraph ++;
dataAcx ++;
}
});
...
}
现在它的摩擦价值,但不会改变用户界面,因为你需要在单独的线程中进行这种用户界面更新操作。您需要将 Thread中
/ Runnable
。在 onClick
& amp; 线程
放置该代码。
请参阅下面的链接: $ b http://karanbalkar.com/2014/05/display-graphs-using-graphview-in-android/ < a>
I have a problem with GraphView not refreshing.. meaning it changes Y value to accomodate for new data but doesn't draw it, just stays on the first data provided, heres the code:
public class MainActivity extends Activity
{
double data = 1;
double xgraph = 5;
GraphViewSeries sensorSeries;
GraphView graphView;
...
@Override
public void onCreate(Bundle savedInstanceState)
{
...
sensorSeries = new GraphViewSeries(new GraphViewData[] {
new GraphViewData(1, 2.0d)
, new GraphViewData(2, 1.5d)
, new GraphViewData(3, 2.5d)
, new GraphViewData(4, 1.0d)
});
graphView = new LineGraphView(this,"TEST");
graphView.addSeries(sensorSeries);
LinearLayout layout = (LinearLayout) findViewById(R.id.graph2);
graphView.setViewPort(0, 20);
layout.addView(graphView);
refreshButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
sensorSeries.appendData(new GraphViewData(xgraph, data), false);
graphView.redrawAll();
myLabel.setText(""+data+" "+xgraph);
xgraph++;
dataAcx++;
}
});
...
}
Right now its chafing values but not changing UI, because you need to do such UI update operations in separate thread. You need to place all your code which is inside onClick
in Thread
/Runnable
. Create Thread
object inside onClick
& place that code.
Refer below link :
http://karanbalkar.com/2014/05/display-graphs-using-graphview-in-android/
这篇关于GraphView不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!