0
I got the following array JS
on the return of $.ajax
shrunk from PHP (json_encode($array)
):
{
"17":[
{
"data":"2019-03-01",
"ofetas":"22.65",
"decisoes":"6"
},
{
"data":"2019-03-03",
"ofetas":"55.33",
"decisoes":"3"
},
{
"data":"2019-03-05",
"ofetas":"30.45",
"decisoes":"2"
}
],
"18":[
{
"data":"2019-03-02",
"ofetas":"78.39",
"decisoes":"0"
},
{
"data":"2019-03-05",
"ofetas":"30.00",
"decisoes":"1"
}
]
}
But from that array
, need to create a object that will meet a requisition:
In the end, the object needs to be of the type below in order to use only the date and decision indices of each array
var datasets =
[
{
label: "17",
data: [ {
x: "2019/03/01",
y: 6
}, {
x: "2019/03/03",
y: 3
}, {
x: "2019/03/01",
y: 2
} ]
} ,
{
label: "18",
data: [
{
x: "2019/03/02",
y: 0
}, {
x: "2019/03/05",
y: 1
} ]
}
];
In this case, how would the foreach
(iteration) in the array
of the opening of the question in such a way that it object above?
I even started doing the foreach
but I ran into each other square brackets interns who gave me a sense of string.
Hi, fantastic. But this object does not accept the quotation marks in the indices, will it work? It is the generation of graphics. Notice by the example I posted!
– Carlos Rocha
The pas should make no difference. Some mistake?
– Costamilam
Boy tested here and did not fail no. It is that in the documentation of the biblicoteca has no quotation marks. If it is too complicated it leaves. But if you lock up, please remove the quotes?
– Carlos Rocha
Carlos, quotation marks are only for marking when you are declaring an object. Quotation marks do not exist on the object itself after it is built. There is no difference between a constructed object using quotation marks in the declaration, and an object built without quotation marks.
– Andre
On the quotation marks, understand better by reading here, here and here
– hkotsubo