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

时间:2015-09-08 05:41:08

标签: android graph android-graphview

我需要在运行时暂停并在中间开始一个折线图。我正在使用GraphView库。我的线图正确显示图表。我需要实现暂停并从暂停点开始。如何做到这一点?
提前谢谢..

我在下面添加了我的代码。

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);
        }

0 个答案:

没有答案