score:0

i think you are stuck at to create piedata for the chart form json. here is the solution:

your json string:

$json = '[{"clinic_name":"clinic 1","total_checked_up":"4"},{"clinic_name":"clinic 2","total_checked_up":"0"},{"clinic_name":"clinic 3","total_checked_up":"0"},{"clinic_name":"clinic 4","total_checked_up":"0"}]';

first convert it to array:

$array = json_decode($json);

declare the empty variable:

$string_array = '';

loop threw the array:

foreach($array as $single_array){

    $string_array[] = array(
    'value'=>$single_array->total_checked_up,
    'color'=>'#f56954',
    'highlight'=>'#f56954',
    'label'=>$single_array->clinic_name
    );  
}

convert the array into json again to get your desired piedata:

var piedata  = json_encode($string_array);

this is how your piedata data look like.

[
    {
        "value": "4",
        "color": "#f56954",
        "highlight": "#f56954",
        "label": "clinic 1"
    },
    {
        "value": "0",
        "color": "#f56954",
        "highlight": "#f56954",
        "label": "clinic 2"
    },
    {
        "value": "0",
        "color": "#f56954",
        "highlight": "#f56954",
        "label": "clinic 3"
    },
    {
        "value": "0",
        "color": "#f56954",
        "highlight": "#f56954",
        "label": "clinic 4"
    }
]

Related Query

More Query from same tag