How to provide GraphViewDataInterface as a input to method in graphview

376 Views Asked by At

I am trying to add a graph to my project for that purpose I am using GraphView library.

My issue here is in one of the methods drawseries expecting an interface (GraphViewDataInterface) which I am confused on how to provide as a input.

draw series method input parameters:

The method drawSeries(Canvas, GraphViewDataInterface[], float, float, float, double, double, double, double, float, GraphViewSeries.GraphViewSeriesStyle)

I have provided all parameters but struck at GraphViewDataInterface.

How can I provide an interface as a parameter to the method?

Code:

public class graph extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.graph);

        BarGraphView bgv=new BarGraphView(getApplicationContext(), "firstgraph");
        Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(b);
        bgv.drawSeries(c,
                 GraphViewDataInterface[] {10.0,10.0}, (float) 1.0,
                (float) 1.0,
                (float) 1.0,
                1.0,
                1.0,
                1.0,
                1.0,
                (float) 1.0,
                new GraphViewSeries.GraphViewSeriesStyle(1, 1));

            LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout1);
            layout.addView(bgv);
    }
1

There are 1 best solutions below

2
On BEST ANSWER

I'm not sure what exactly you want to do. drawSeries is an intern method. normally you never call it explicit. Take a look at the examples and the documentation.

Anyway, the GraphViewDataInterface is used to return just the x and y values. You could provide your own class and methods to do so. But normally you use the class GraphViewData that already implements that interface.

import com.jjoe64.graphview.GraphView.GraphViewData;
//...
// create data array
GraphViewDataInterface[] data = new GraphViewDataInterface[] {
  new GraphViewData(0, 1),
  new GraphViewData(1, 5),
  new GraphViewData(2, 3)
};