添加新数据时不会更新GraphView [英] GraphView is not updated when new data is added

查看:207
本文介绍了添加新数据时不会更新GraphView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 GraphView 在添加新数据时没有更新,它会更改Y值以适应新数据,但它不会绘制它们,这是代码:

I have a GraphView that is not updated when new data is added, it changes the Y value to accommodate for the new data, but it doesn't draw them, here is 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++;
            }
        });
    }
    ...
}


推荐答案

现在它的擦伤值但不改变UI,因为你需要在单独的线程中进行这样的UI更新操作。您需要在线程中放置内的所有代码线程 / Runnable 。在中创建线程对象onClick &放置该代码。

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.

请参阅以下链接:

http://karanbalkar.com/2014/05/display-graphs-using-graphview-in-android/

这篇关于添加新数据时不会更新GraphView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆