Android 如何显示firebase数据库中带有日期时间值的x轴和带有毫秒值的y轴
这是我将点值放入firebase并从firebase获取数据的代码部分。我想用当天的时间值显示x轴值,用该值显示y轴。我应该如何使用这个名为“implementation com.github.PhilJay:MPAndroidChart:v3.0.3”的库Android 如何显示firebase数据库中带有日期时间值的x轴和带有毫秒值的y轴,android,firebase,android-studio,firebase-realtime-database,Android,Firebase,Android Studio,Firebase Realtime Database,这是我将点值放入firebase并从firebase获取数据的代码部分。我想用当天的时间值显示x轴值,用该值显示y轴。我应该如何使用这个名为“implementation com.github.PhilJay:MPAndroidChart:v3.0.3”的库 private void setListeners(){ btn_insert.setOnClickListener(新视图.OnClickListener(){ @凌驾 公共void onClick(视图){ 字符串id=referenc
private void setListeners(){
btn_insert.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
字符串id=reference.push().getKey();
long xl=新日期().getTime();
int x=(int)xl;
//long now=TimeUnit.millides.toHours(System.currentTimeMillis());
//int x=(int)现在;
//字符串x=字符串的值(x1);
//intx=Integer.parseInt(xValue.getText().toString());
int y=Integer.parseInt(yValue.getText().toString());
//PointValue PointValue=新的PointValue(x,y);
PointValue PointValue=新的PointValue(x,y);
reference.child(id).setValue(pointValue);
}
});
}
私有void DataShow(){
ValueEventListener postListener=新的ValueEventListener(){
@凌驾
公共void onDataChange(DataSnapshot DataSnapshot){
//获取Post对象并使用这些值更新UI
条目[]dp=新条目[(int)dataSnapshot.getChildrenCount()];
int指数=0;
整数和=0;
int max=0;
int min=0;
对于(DataSnapshot myDataSnapshot:DataSnapshot.getChildren())
{
PointValue PointValue=myDataSnapshot.getValue(PointValue.class);
dp[index]=新条目(index+1,pointValue.getyValue());
添加(dp[索引]);
索引++;
sum+=pointValue.getyValue();
如果(最小值==0&&max==0){
min=pointValue.getyValue();
max=pointValue.getyValue();
}
如果(pointValue.getyValue()>max)max=pointValue.getyValue();
如果(pointValue.getyValue(),那么使用此代码时的行为是什么?问题是,我传递给firebase的时间值,如何在x轴上显示。这是一个难题。。。
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);
}