Java Question Help needed wrapping Library

walterf25

Expert
Licensed User
Longtime User
Hello everyone, i need to wrap this Graph Plotting library, I know that a user by the name of XverHelstX
has already wrapped this library but is a paid library, I need to wrap this library for a work project i'm currently working on, anyhow what I need help is figuring out how to pass the X and Y parameters to the graph in an array. this is the java code used to add the datapoints to the graph!
B4X:
exampleseries = new GraphViewSeries(new GraphViewData[]{
            new GraphViewData(1, 1.0)
            , new GraphViewData(2, 1.5d)
            , new GraphViewData(2.5, 3.0d) // another frequency
            , new GraphViewData(3, 2.5d)
            , new GraphViewData(4, 1.0d)
            , new GraphViewData(5, 3.0d)
    });

As you guys can see this datapoints are fixed, I need to figure out how to pass different values all the time, for example if I'm reading the voltage via bluetooth i'd like to pass an array of values to the code above.
and this is how the graphview is added:

B4X:
public static LineGraphView AddGraph(BA ba, String GraphTitle){
        graphview = new LineGraphView(ba.context, GraphTitle);
        graphview.addSeries(exampleseries);
        return graphview;
    }}
Any Help and all advices on how to go around this will be greatly appreciated.

Thanks All!
Walter
 

thedesolatesoul

Expert
Licensed User
Longtime User
Its an array of GraphViewData, you might just pass the x,y values and create the GraphViewData inside.
For instance,
Dim points(10,2) as Int 'where there are 10 points, but the second indice represents x/y

Pass it to the java sub:
B4X:
GraphViewData GVD(10);
GVD(0) = new GraphViewData(points(0,0), points(0,1);
GVD(0) = new GraphViewData(points(1,0), points(1,1);
...and so on
exampleseries = new GraphViewSeries(GVD);
 

thedesolatesoul

Expert
Licensed User
Longtime User
I havent written java in a while so this code is probably broken:

B4X:
void CreateGVS(int[][] points, int length){
GraphViewData[] GSV = new GraphViewData[length];
for (int i = 0;i < length;i++) {
   GSV[i] = new GraphViewData(points[i][0], points[i][1]);
}
exampleseries = new GraphViewSeries(GSV);
 
Top