我正在研究从服务器获取ECG值并在Android中绘制ECG图的项目。现在,我能够绘制图形,但是无法在其上添加注释。就像我想在特定数据点上添加“ NP”(正常脉冲)和AP(异常脉冲)。 我正在使用这段代码从服务器获取数据并绘制图形。 私有无效GetECGProcessedData(){
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Send Report for Processing....!!!");
progressDialog.show();
progressDialog.setCancelable(true);
StringRequest stringRequest = new StringRequest(Request.Method.POST, "http://20.188.98.39/cardiccare/get_p.php",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
progressDialog.dismiss();
try {
JSONObject obj = new JSONObject(response);
JSONArray array = obj.getJSONArray("response_array");
for (int i = 0; i < array.length(); i++) {
JSONObject jsonObject = array.getJSONObject(i);
Pdata = jsonObject.getString("pdata");
}
// Storing value in array after removing the comma in the string.
final String[] elements = Pdata.split(",");
fixedLenghtList = Arrays.asList(elements);
listOfString = new ArrayList<String>(fixedLenghtList);
// we get graph view instance
GraphView graph = (GraphView) findViewById(R.id.graphview);
// set manual X bounds
graph.getViewport().setYAxisBoundsManual(true);
// first series is a line
DataPoint[] points = new DataPoint[listOfString.size()];
for (int i = 0; i < points.length; i++) {
points[i] = new DataPoint(i, Double.parseDouble(listOfString.get(i)));
}
LineGraphSeries<DataPoint> series = new LineGraphSeries<>(points);
// set manual X bounds
graph.getViewport().setYAxisBoundsManual(true);
graph.getViewport().setMinY(-20);
graph.getViewport().setMaxY(20);
graph.getViewport().setXAxisBoundsManual(true);
graph.getViewport().setMinX(4);
graph.getViewport().setMaxX(3700);
// enable scaling and scrolling
graph.getViewport().setScalable(true);
graph.getViewport().setScalableY(true);
graph.addSeries(series);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.dismiss();
Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("rid", String.valueOf(1143));
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
PlotECG();
}