View Single Post
Old November 8th, 2012, 03:24 PM   #1 (permalink)
Valten1992
Junior Member
Thread Author (OP)
 
Valten1992's Avatar
 
Join Date: Feb 2012
Location: Ireland
Posts: 43
 
Device(s): Samsung Galaxy mini
Carrier: Not Provided

Thanks: 6
Thanked 3 Times in 3 Posts
Default 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);
Valten1992 is offline  
Reply With Quote