这是代码的一部分,我将点值放到firebase中并从firebase中获取数据。我想在日期上显示带有时间值的x轴值,并在值上显示y轴。我应该如何使用这个名为“ implementation com.github.PhilJay:MPAndroidChart:v3.0.3”的库
private void setListeners() {
btn_insert.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
String id=reference.push().getKey();
long xl=new Date().getTime();
int x=(int) xl;
// long now = TimeUnit.MILLISECONDS.toHours(System.currentTimeMillis());
// int x=(int) now;
// String x= String.valueOf(x1);
// int x=Integer.parseInt(xValue.getText().toString());
int y=Integer.parseInt(yValue.getText().toString());
// PointValue pointValue=new PointValue(x,y);
PointValue pointValue=new PointValue(x,y);
reference.child(id).setValue(pointValue);
}
});
}
private void DataShow(){
ValueEventListener postListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Get Post object and use the values to update the UI
Entry[] dp= new Entry[(int) dataSnapshot.getChildrenCount()];
int index=0;
int sum=0;
int max=0;
int min=0;
for(DataSnapshot myDataSnapshot: dataSnapshot.getChildren())
{
PointValue pointValue=myDataSnapshot.getValue(PointValue.class);
dp[index] = new Entry(index+1, pointValue.getyValue());
yValues.add(dp[index]);
index++;
sum+=pointValue.getyValue();
if(min==0 && max==0){
min=pointValue.getyValue();
max=pointValue.getyValue();
}
if(pointValue.getyValue()>max) max=pointValue.getyValue();
if(pointValue.getyValue()<min) min=pointValue.getyValue();
}
int Avg=0;
Log.v(TAG,"Index: "+index);
if(index!=0)
Avg=sum/index;
values.setText("Minimum value : "+ min+" ml"+"\n Average Value : "+ Avg +" ml"+"\n Maximum Value : "+max+" ml"+"\n");
set=createSet();
data.addDataSet(set);
data.notifyDataChanged();
mChart.setData(data);
mChart.notifyDataSetChanged();
mChart.animateX(3000);
mChart.invalidate();
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
// ...
}
};
reference.addValueEventListener(postListener);
}
请提供指导以完成此任务。
谢谢