i have the following mongoose schema:
// UnitDataLogSchema Schema
var UnitDataLogSchema = new mongoose.Schema({
serialnumber: {
type: String
},
timestamp: Number,
temperatures: []
});
so i will get a collection with the following data:
{ "_id" : 1, "timestamp": 100, "temperatures" : [1,2,3] }
{ "_id" : 1, "timestamp": 200, "temperatures" : [4,5,6] }
{ "_id" : 1, "timestamp": 300, "temperatures" : [7,8,9] }
{ "_id" : 1, "timestamp": 400, "temperatures" : [10,11,12] }
....
how can i aggregate this collection so i can have this final object:
{
zonetemperatures:[
[ [100,1],[200,4],[300,7],[400,10] ],...
[ [100,2],[200,5],[300,8],[400,11] ],...
[ [100,3],[200,6],[300,9],[400,12] ],...
]
}
with this i will have an array that each element is a serie in the Highstock chart.
and i can easily set data in the chart like this:
for (let index = 0; index < zonetemperatures.length; index++) {
chart.series[index].setData(zonetemperatures[index]);
}
chart.redraw();