-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main2Activity.java
63 lines (47 loc) · 1.72 KB
/
Main2Activity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.example.weighttracker;
import androidx.appcompat.app.AppCompatActivity;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Bundle;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.utils.ColorTemplate;
import java.util.ArrayList;
public class Main2Activity extends AppCompatActivity {
BarChart barChart;
BarData barData;
BarDataSet bardataSet;
ArrayList barEntries;
DatabaseHelper myDb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
myDb = new DatabaseHelper(this);
barChart = (BarChart)findViewById(R.id.Barchart);
getEntries();
bardataSet = new BarDataSet(barEntries,"Data Set");
barData = new BarData(bardataSet);
barChart.setData(barData);
bardataSet.setColors(ColorTemplate.MATERIAL_COLORS);
bardataSet.setValueTextColor(Color.BLACK);
bardataSet.setValueTextSize(16f);
}
public void getEntries(){
barEntries = new ArrayList<>();
Cursor cr = myDb.getallData();
if(cr.getCount()==0){
barEntries.add(new BarEntry(0f,0));
}else{
float f = 1f;
while(cr.moveToNext()){
double weight = cr.getDouble(2);
float m = (float)weight;
barEntries.add(new BarEntry(f,m));
f+=1f;
}
}
}
}