I want to plot a diagram in android with GraphView library http://www.android-graphview.org/ . but the number of points of diagram is more than 12000 and it isn't possible to add all single points manually. my data saved in storage (with custom format) as shown below :
0.000,116.288
0.008,122.422
0.016,126.721
...
I get the data from https://physionet.org/cgi-bin/atm/ATM with this setting:
Signals:ABP
Time format:seconds
Toolbox:Export signals as CSV
and I need to read them from file and convert data as shown below for plotting diagram :
new DataPoint(0.000,116.288),
new DataPoint(0.008,122.422),
new DataPoint(0.016,126.721)...
I copied my CSV file in asset folder and read it. then I convert them into Double and try to plot diagram with data. but the diagram is not correct . I think the problems appears when I want to add new Datapoint, because it need to add a comma "," after each line
pls advise how I can add it?
besides,sometimes after running the application it has stopped.
java code:
public class Plot_Activity extends AppCompatActivity {
String valXY[];
Double Xval;
Double Yval;
GraphView graph;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GraphView graph = (GraphView) findViewById(R.id.graph);
try {
reader=new BufferedReader(new InputStreamReader(getAssets().open("plot/b00_2010_abp_5s.txt")));
String mline;
while((mline=reader.readLine())!=null)
{
valXY = mline.split(",");
Xval =Double.parseDouble(valXY[0]);
Yval =Double.parseDouble(valXY[1]);
DataPoint[] dp = new DataPoint[valXY.length];
for (int i = 0; i < valXY.length; i++)
{
dp[i] = new DataPoint(Xval, Yval);
}
LineGraphSeries<DataPoint> series = new LineGraphSeries<>(dp);
graph.addSeries(series);
}
} catch (IOException e)
{
e.printStackTrace();
}
graph.getViewport().setXAxisBoundsManual(true);
graph.getViewport().setMinX(0);
graph.getViewport().setMaxX(1);
graph.getViewport().setScrollable(true); // enables horizontal scrolling
graph.getViewport().setScrollableY(true); // enables vertical scrolling
}
}
XML code:
<com.jjoe64.graphview.GraphView
android:id="@+id/graph"
android:layout_marginRight="11dp"
android:layout_width="wrap_content"
android:layout_height="280dp"
thank in advance