I have been hitting my head against a wall all day trying to solve this problem and also having searched on here i have found nothing as of yet.
My current object that is returned from an API is structured as so, i have over 2000 data points for each device:
{ "DeviceA": [
{ "device_id": "DeviceA",
"time": "2021-01-23T18:43:14Z",
"temperature": 1.875,
"strength": -14.827574,
"maturity": 105.904513
},
{ "device_id": "ExampleB",
"time": "2021-01-23T18:53:14Z",
"temperature": 1.35,
"strength": -145.64274540827574,
"maturity": 10.904513
},
]
"DeviceB": [
{ "device_id": "DeviceB",
"time": "2021-01-23T18:43:14Z",
"temperature": 1.5,
"strength": -120.64274540827574,
"maturity": 3233.04513
},
{ "device_id": "ExampleB",
"time": "2021-01-23T18:53:14Z",
"temperature": 1.875,
"strength": -17.4274540827574,
"maturity": 10554.268851904513
},
}
And how i want it
[
{
"id": "DeviceA"
"Data": [
{
"x": "time"
"y": "temperature"
}
]
}
{
"id": "DeviceB"
"Data": [
{
"x": "time"
"y": "temperature"
}
]
}
]
I have tried nesting mapped arrays, millions of things but i can never get the right output. Any help would be massively appreciated!
Edit:
Apologies i had not included some code for what i was working on
const graphAllTempVTime = () => {
const sensorTempVTimeMapped = Object.entries(sensorDatasFromCast).map(
(items, index) => ({
id: items[0],
data: [
{
x: items[1].time,
y: items[1].temperature,
},
],
})
)
return sensorTempVTimeMapped
}
However this produces the output of:

