Refreshing my static chart in my Activity?


  1. Valten1992

    Valten1992 Active Member

    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 (Text):
    1.  
    2. Timer tim = new Timer();
    3.  
    4. verlabels = new String[] {"here","there"};
    5.         horlabels = new String[] {"here","there"};
    6.         graphView = new GraphView(this, fvalues, description,horlabels, verlabels, GraphView.LINE);
    7.         layout.addView(graphView);
    8.  
    9. tim.scheduleAtFixedRate(new TimerTask() {
    10.             @Override
    11.             public void run() {
    12.            
    13.                 try {
    14.                     float f = (float) 2.0;
    15.                     values.add(f);
    16.                     verlabels = new String[] { };
    17.                     horlabels = new String[] { };
    18.                    
    19.                     fvalues = new float[values.size()];
    20.                    
    21.                     for(int j = 0; j<values.size(); j++) {
    22.                        
    23.                         fvalues[j] = values.get(j);
    24.                     }
    25.                     Log.e("here", fvalues.length+"");
    26.                    
    27.                 } catch (Exception e) {
    28.                     Log.e("error", "error");
    29.                 }
    30.                
    31.                 runOnUiThread(new Runnable() {
    32.                     public void run() {
    33.                        
    34.                         graphView = new GraphView(context, fvalues, description+" values",horlabels, verlabels, GraphView.LINE);
    35.                    
    36.                         graphView.invalidate();
    37.                     }
    38.                 });
    39.                
    40.             }
    41.         }, 0, 5000);
    42.  
    43.  
    44.  

    Advertisement

Share This Page