I am creating a Time Cartesian Chart from Chart.js, I need to get the data as json format, however I need to first generate a php array and use json_encode() in order to get the following json. Does anyone knows what the php array be like inorder to get the following JSON?
data: [{
x: '2021-11-06',
y: 50
}, {
x: '2021-11-07',
y: 60
}, {
x: '2021-11-07',
y: 20
}]
Thank you very much!
CodePudding user response:
Try this,
$data = [
[
'x' => '2021-11-06',
'y'=> 50
],
[
'x' => '2022-11-07',
'y'=> 60
],
[
'x' => '2023-11-07',
'y'=> 20
]
];
$data = json_encode($data);