Android的graphview不会自动更新 [英] Android graphview not automatically updating

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

问题描述

我使用的是GraphView图书馆,我不能让图重绘自身时,我更新系列(或者更换一个新的系列)。它似乎只重画自己,当我触摸屏幕。这是我更新功能。

 私人无效updateGraph(动物)
{
    Toast.makeText(getApplicationContext(),更新图形,Toast.LENGTH_SHORT).show();
    GraphViewData [] newData =新GraphViewData [2];
    newData [0] =新GraphViewData(0,a.getAvg());
    newData [1] =新GraphViewData(1,0.2);    GraphViewSeries newSeries =新GraphViewSeries(a.getName(),dStyle,newData);    graph.removeSeries(exampleSeries);
    graph.addSeries(newSeries);
    //更新水平值
    //graph.setHorizo​​ntalLabels(new的String [] {a.getName()});
}


解决方案

我想它了...

  //测试随机的Y值
    双RND = generator.nextDouble();    //圆是一个增量值(1,2,3 ...)
    GraphViewData newData =新GraphViewData(圆,RND);    exampleSeries.appendData(newData,FALSE);
    graph.redrawAll();

I am using the GraphView Library and I cant get the graph to redraw itself when I update the series (or replace the series with a new one). It only seems to redraw itself when I touch the screen. Here is my update function.

private void updateGraph(Animal a)
{
    Toast.makeText(getApplicationContext(), "Updating Graph", Toast.LENGTH_SHORT).show();
    GraphViewData[] newData = new GraphViewData[2];
    newData[0] = new GraphViewData(0,a.getAvg());
    newData[1] = new GraphViewData(1,0.2);

    GraphViewSeries newSeries = new GraphViewSeries(a.getName(),dStyle,newData);

    graph.removeSeries(exampleSeries);
    graph.addSeries(newSeries);
    //update horizontal value
    //graph.setHorizontalLabels(new String[]{a.getName()});
}

解决方案

I figured it out...

//test random y value
    double rnd = generator.nextDouble();

    // round is an incremental value (1,2,3...)
    GraphViewData newData = new GraphViewData(round,rnd);

    exampleSeries.appendData(newData, false);
    graph.redrawAll();

这篇关于Android的graphview不会自动更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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