How to provide GraphViewDataInterface as a input to method in graphview Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to provide GraphViewDataInterface as a input to method in graphview without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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

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)
};
We are here to answer your question about How to provide GraphViewDataInterface as a input to method in graphview - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji