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