• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Refreshing my static chart in my Activity?

I need to have a chart in my Android activity to pass data into as my app runs and the chart will update accordingly.

For this I am using Graphview, a static Graph that is entirely client side. When the activity loads the Graph shall be blank but will invalidate and redraw itself when data passes into it on a timer delay. At the moment I just want to get the view refresh going so the Graph redraws itself with the new data passed in, but no luck so far. I'm kinda rusty with Android after being away for a few months so it may be something obvious:

Code:
Timer tim = new Timer();

verlabels = new String[] {"here","there"};
        horlabels = new String[] {"here","there"};
        graphView = new GraphView(this, fvalues, description,horlabels, verlabels, GraphView.LINE);
        layout.addView(graphView);

tim.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
            
                try {
                    float f = (float) 2.0;
                    values.add(f);
                    verlabels = new String[] { };
                    horlabels = new String[] { };
                    
                    fvalues = new float[values.size()];
                    
                    for(int j = 0; j<values.size(); j++) {
                        
                        fvalues[j] = values.get(j);
                    }
                    Log.e("here", fvalues.length+"");
                    
                } catch (Exception e) {
                    Log.e("error", "error");
                }
                
                runOnUiThread(new Runnable() {
                    public void run() {
                        
                        graphView = new GraphView(context, fvalues, description+" values",horlabels, verlabels, GraphView.LINE);
                   
                        graphView.invalidate();
                    }
                });
                
            }
        }, 0, 5000);
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones