Guest User

Untitled

a guest
Dec 14th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. private void init(){
  2. bGSeries = new PointsGraphSeries<>();
  3.  
  4. btnAdd.setOnClickListener(new View.OnClickListener() {
  5. @Override
  6. public void onClick(View view) {
  7. if(!bg.getText().toString().equals("")){
  8. double mbg = Double.parseDouble(bg.getText().toString());
  9. if(mbg > 300){
  10. toastMessage("You should be going to the ER not using this app.");
  11. }
  12. bgValueArray.add(new bgValue(mbg));
  13. init();
  14. }else {
  15. toastMessage("You must enter a BG.");
  16. }
  17. }
  18. });
  19.  
  20. if(bgValueArray.size() != 0){
  21. createGraph();
  22. }else{
  23. Log.d(TAG, "onCreate: No data to plot.");
  24. }
  25. }
  26.  
  27. private void createGraph()
  28.  
  29. {
  30.  
  31. //Adds data to the graph
  32. for(int i = 0;i <bgValueArray.size(); i++){
  33. try{
  34. double x = bgValueArray.get(i).getBg();
  35. bGSeries.appendData(new DataPoint(x,x),true, 50);
  36. }catch (IllegalArgumentException e){
  37. Log.e(TAG, "createScatterPlot: IllegalArgumentException: " + e.getMessage() );
  38. }
  39. }
  40.  
  41. //properties of the line graph
  42. bGSeries.setShape(PointsGraphSeries.Shape.RECTANGLE);
  43. bGSeries.setColor(Color.RED);
  44. bGSeries.setSize(15f);
  45.  
  46. //X Graph Bounds
  47. mLineGraph.getViewport().setYAxisBoundsManual(true);
  48. mLineGraph.getViewport().setMaxY(300);
  49. mLineGraph.getViewport().setMinY(0);
  50.  
  51. //Y Graph Bounds
  52. mLineGraph.getViewport().setXAxisBoundsManual(true);
  53. mLineGraph.getViewport().setMaxX(300);
  54. mLineGraph.getViewport().setMinX(0);
  55.  
  56. mLineGraph.addSeries(bGSeries);
  57. }
Add Comment
Please, Sign In to add comment