Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void init(){
- bGSeries = new PointsGraphSeries<>();
- btnAdd.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if(!bg.getText().toString().equals("")){
- double mbg = Double.parseDouble(bg.getText().toString());
- if(mbg > 300){
- toastMessage("You should be going to the ER not using this app.");
- }
- bgValueArray.add(new bgValue(mbg));
- init();
- }else {
- toastMessage("You must enter a BG.");
- }
- }
- });
- if(bgValueArray.size() != 0){
- createGraph();
- }else{
- Log.d(TAG, "onCreate: No data to plot.");
- }
- }
- private void createGraph()
- {
- //Adds data to the graph
- for(int i = 0;i <bgValueArray.size(); i++){
- try{
- double x = bgValueArray.get(i).getBg();
- bGSeries.appendData(new DataPoint(x,x),true, 50);
- }catch (IllegalArgumentException e){
- Log.e(TAG, "createScatterPlot: IllegalArgumentException: " + e.getMessage() );
- }
- }
- //properties of the line graph
- bGSeries.setShape(PointsGraphSeries.Shape.RECTANGLE);
- bGSeries.setColor(Color.RED);
- bGSeries.setSize(15f);
- //X Graph Bounds
- mLineGraph.getViewport().setYAxisBoundsManual(true);
- mLineGraph.getViewport().setMaxY(300);
- mLineGraph.getViewport().setMinY(0);
- //Y Graph Bounds
- mLineGraph.getViewport().setXAxisBoundsManual(true);
- mLineGraph.getViewport().setMaxX(300);
- mLineGraph.getViewport().setMinX(0);
- mLineGraph.addSeries(bGSeries);
- }
Add Comment
Please, Sign In to add comment