I'm checking last 100000 measurements of humidity and make chart, but on chart I want to show every 100th measurement, how can I modify this code to do this:
firebase.database().ref("Humidity").ref.orderByChild("time").limitToLast(100000).on("child_added",snapshot => {
var a = snapshot.val().wartosc;
var b = (new Date(snapshot.val().time *1000)).toLocaleString("pl-PL");
addData(myChart, b, a);
This should do the trick:
firebase.database().ref("Humidity") // 👈 Remove the extra ref here
.orderByChild("time")
.limitToLast(100000)
.on("value", snapshot => { // 👈 use value instead of child_added
let index = 0;
snapshot.forEach((child) => {
if (index++ % 1000 === 0) { // 👈 check for every 1000th child
var a = child.val().wartosc;
var b = (new Date(child.val().time * 1000)).toLocaleString("pl-PL");
}
addData(myChart, b, a);
})
})
I've marked the main changes, but there may be some smaller changes needed too.