GarphView not working, empty activity
I have included GraphView in my main activity class dynamically. It does not display the result. At startup, the activity remains empty.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//GraphView
int num = 150;
GraphViewData[] data = new GraphViewData[num];
double v=0;
for (int i=0; i<num; i++) {
v += 0.2;
data[i] = new GraphViewData(i, Math.sin(v));
}
GraphView graphView = new LineGraphView(this, "GraphViewDemo");
// add data
GraphViewSeries graphViewSeries=new GraphViewSeries(data);
graphView.addSeries(graphViewSeries);
// set view port, start=2, size=40
graphView.setViewPort(2, 40);
graphView.setScrollable(true);
// optional - activate scaling / zooming
graphView.setScalable(true);
Log.d("2", "closed");
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
layout.addView(graphView);
//GraphhView
}
Mine I will miss something but get nothing.
+3
source to share
1 answer
You need to create a GraphViewData class in your code that implements GraphViewDataInterface
as in the example below:
public class GraphViewData implements GraphViewDataInterface {
private double x,y;
public GraphViewData(double x, double y) {
this.x = x;
this.y = y;
}
@Override
public double getX() {
return this.x;
}
@Override
public double getY() {
return this.y;
}
}
0
source to share