I wrote a mySQL query and then built my JSON data with:
Code: Select all
$result = mysqli_query($query);
$json_array = array();
while($row = mysqli_fetch_assoc($query))
{
$json_array[] = $row;
}
$json = json_encode($json_array, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
[{"series":1,"labels":"asset_1"},{"series":2,"labels":"asset_2"}]
I am trying to set up a pie chart, but Apexcharts requires that the JSON data is in the format:
{
series: [1, 2],
labels: ['asset_1', 'asset_2']
}
What is the best/easiest way to change the format of the JSON data? Any help would be greatly appreciated.