我使用Android Studio https://github.com/PhilJay/MPAndroidChart库完成了Graphs。问题是,
如何使用该库命名轴?
从firebase(如每日,每周,每月)获取数据时,如何使用该库表示图数据?
这些是我的视觉输出
这些是我的密码
public class DrinkActivity extends Fragment {
private LineChart mChart;
EditText yValue,xValue;
Button btn_insert;
FirebaseDatabase database;
DatabaseReference reference;
ArrayList<Entry> yValues;
LineDataSet set1;
public DrinkActivity() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.activity_drink, container, false);
mChart = (LineChart)v.findViewById(R.id.linechart);
xValue=(EditText) v.findViewById(R.id.editText);
yValue=(EditText) v.findViewById(R.id.editText2);
btn_insert=(Button) v.findViewById(R.id.button2);
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
yValues=new ArrayList<>();
database= FirebaseDatabase.getInstance();
reference=database.getReference("ChartTable/LineChart");
setListeners();
return v;
}
private void setListeners() {
btn_insert.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
String id=reference.push().getKey();
int x=Integer.parseInt(xValue.getText().toString());
int y=Integer.parseInt(yValue.getText().toString());
PointValue pointValue=new PointValue(x,y);
reference.child(id).setValue(pointValue);
}
});
}
@Override
public void onStart() {
super.onStart();
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Entry[] dp= new Entry[(int) dataSnapshot.getChildrenCount()];
int index=0;
for(DataSnapshot myDataSnapshot: dataSnapshot.getChildren())
{
PointValue pointValue=myDataSnapshot.getValue(PointValue.class);
dp[index]=new Entry(pointValue.getxValue(),pointValue.getyValue());
yValues.add(dp[index]);
index++;
}
set1=new LineDataSet(yValues,"Data set1");
set1.setFillAlpha(110);
set1.setColor(Color.BLUE);
set1.setLineWidth(3f);
set1.setValueTextSize(10f);
LineData data=new LineData(set1);
mChart.setData(data);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
谢谢(请考虑我是android studio和firebase的初学者)
(很抱歉在同一问题上问两个不同的问题)