3

I have implemented GraphView in my Main activity class dynamically. Not result is shown in it. The activity remains blank when launched.

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
}

My be i miss something, but i don't get anything.

J Steven Perry
  • 1,711
  • 1
  • 17
  • 28

1 Answers1

0

You need to create a GraphViewData class in your code that implements GraphViewDataInterface, like 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;
    }   
}
Michele La Ferla
  • 6,775
  • 11
  • 53
  • 79
maria
  • 21
  • 2