Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在GraphView运行时暂停并启动实时线图?_Android_Graph_Android Graphview - Fatal编程技术网

Android 如何在GraphView运行时暂停并启动实时线图?

Android 如何在GraphView运行时暂停并启动实时线图?,android,graph,android-graphview,Android,Graph,Android Graphview,我需要在运行时暂停并在中间启动一个线图。我正在使用图形视图< /C>库。我的折线图正确地显示了图形。我需要实现暂停,并从暂停的点开始。如何做到这一点? 先谢谢你 我在下面添加了我的代码 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEAT

我需要在运行时暂停并在中间启动一个线图。我正在使用<代码>图形视图< /C>库。我的折线图正确地显示了图形。我需要实现暂停,并从暂停的点开始。如何做到这一点?
先谢谢你

我在下面添加了我的代码

protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                    requestWindowFeature(Window.FEATURE_NO_TITLE);
                    setContentView(R.layout.fhrlistitemgraph);
                    String data = getIntent().getExtras().getString("data");
                    GraphView graph = (GraphView) findViewById(R.id.llgraphview);
                    series = new LineGraphSeries<DataPoint>();
                    graph.addSeries(series);

                    // customize a little bit viewport
                    Viewport viewport = graph.getViewport();
                    viewport.setYAxisBoundsManual(true);
                    viewport.setMinY(0);
                    viewport.setMaxY(200);
                    //viewport.setYAxisBoundsManual(true);
                    viewport.setScalable(true);
                    viewport.setScrollable(true);
            }
        @Override
                protected void onResume() {
                    super.onResume();
                    // we're going to simulate real time with thread that append data to the
                    // graph
                    new Thread(new Runnable() {

                        @Override
                        public void run() {
                            String value = null;
                            String[] data = data.replaceAll("\\[", "").replaceAll(" ", "").replaceAll("\\]", "").split(",");


                            // we add 100 new entries
                            for (int i = 0; i < data.length; i++) {
                                final int j;
                                j=i;
                                value = data[i];
                                final String values;
                                values = value;
                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        addEntry(j,values);
                                    }
                                });

                                // sleep to slow down the add of entries
                                try {
                                    Thread.sleep(600);
                                } catch (InterruptedException e) {
                                    // manage error ...
                                }
                            }
                        }
                    }).start();

                }
    private void addEntry(int i,String value) {
            // here, we choose to display max 10 points on the viewport and we
            // scroll to end
            series.appendData(new DataPoint(i, Integer.valueOf(value)), true, 5);
        }
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(窗口。功能\u无\u标题);
setContentView(R.layout.fhrlistitemgraph);
字符串数据=getIntent().getExtras().getString(“数据”);
GraphView graph=(GraphView)findViewById(R.id.llgraphview);
系列=新的LineGraphSeries();
图.addSeries(系列);
//自定义一点视口
Viewport=graph.getViewport();
viewport.setYAxisBoundsManual(true);
viewport.setMinY(0);
viewport.setMaxY(200);
//viewport.setYAxisBoundsManual(true);
viewport.setScalable(true);
viewport.setScrollable(true);
}
@凌驾
受保护的void onResume(){
super.onResume();
//我们将使用将数据附加到
//图表
新线程(newrunnable()){
@凌驾
公开募捐{
字符串值=null;
String[]data=data.replaceAll(“\\[”,”).replaceAll(“,”).replaceAll(“\\]”,“).split(“,”);
//我们添加了100个新条目
对于(int i=0;i
如果停止线程,您甚至停止了图形,当您重新启动线程时,图形也会重新启动以显示数据。 您可以使用UI中的按钮停止线程

在我的例子中,我插入了一个布尔值来停止图的更新,因为线程不仅是这样,还需要其他计算,当值为true时,图会更新,当值为false时,图会停止。按下UI中的按钮时,布尔值会发生变化

boolean updateGraph = true;
if(updateGraph=true){
    series.appendData(new DataPoint(countx++, usedramd), true, 60);
}

使用该按钮,您可以更改boolean updateGraph的值。

如果停止线程,您甚至停止了图形,当您重新启动线程时,图形也会重新启动以显示数据。 您可以使用UI中的按钮停止线程

在我的例子中,我插入了一个布尔值来停止图的更新,因为线程不仅是这样,还需要其他计算,当值为true时,图会更新,当值为false时,图会停止。按下UI中的按钮时,布尔值会发生变化

boolean updateGraph = true;
if(updateGraph=true){
    series.appendData(new DataPoint(countx++, usedramd), true, 60);
}
使用该按钮,您可以更改boolean updateGraph的值