private String[] mLabels = {"", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
"21", "22", "23", "24", "",};
private float[][] mValues =
{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0},
{85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f,
85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f,
85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f, 85f}};
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
dateInizioGiorno = cal.getTime();
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
cal.set(Calendar.MILLISECOND, 999);
dateFineGiorno = cal.getTime();
// Firestore
mFirestore = FirebaseFirestore.getInstance();
mFirestore.collection("ristoranti/" + uid + "/ordini")
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.w("Firebase", "Listen failed.", e);
return;
}
for (DocumentSnapshot doc : value) {
if (doc.get("data") != null) {
SimpleDateFormat sdf = new SimpleDateFormat("HH");
int ora = Integer.parseInt(sdf.format(doc.getDate("data"))) + 3; // in base al fuso orario
float totale = Float.valueOf(String.valueOf(doc.getDouble("totale")));
mValues[0][ora] = mValues[0][ora] + totale;
Log.d("linea", Float.toString(totale) + " " + ora);
}
}
show();
}
});
public void show() {
// linea da dove a dove
LineSet dataset = new LineSet(mLabels, mValues[0]);
dataset.setColor(Color.parseColor("#8D4DE8"))
.setThickness(Tools.fromDpToPx(3))
.setSmooth(true)
.beginAt(inizioPunti)
.endAt(finePunti);
// punti bianchi nella linea
for (int i = 0; i < mLabels.length; i += step) {
Point point = (Point) dataset.getEntry(i);
point.setColor(Color.parseColor("#ffffff"));
point.setStrokeColor(Color.parseColor("#8D4DE8"));
// nei punti i il cerco è più grande
//if (i == 10 || i == 20 || i == 30) point.setRadius(Tools.fromDpToPx(6));
}
mChart.addData(dataset);
Paint thresPaint = new Paint();
thresPaint.setColor(Color.parseColor("#000000"));
thresPaint.setStyle(Paint.Style.STROKE);
mChart.setGrid(5, 0, thresPaint);
mChart.setXLabels(AxisRenderer.LabelPosition.OUTSIDE)
.setAxisBorderValues(0, 200)
.setStep(40)
.show(new Animation().fromXY(0, .5f));
}
I have to do a system to get prices from firebase database and display on chart. When i add or edit a record, there is a method on firebase OnEvent to get records when some records have been changed, but i get this error:
Process: easyfood.gz.easyfoodcontrolpanel, PID: 6410
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.get(ArrayList.java:437)
at com.db.chart.view.LineChartView.defineRegions(LineChartView.java:159)
at com.db.chart.view.ChartView$1.onPreDraw(ChartView.java:224)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2337)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1386)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6733)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
I have to do a system to get prices from firebase database and display on chart. When i add or edit a record, there is a method on firebase OnEvent to get records when some records have been changed, but i get this error: