Hello everyone, I need to build a array
as follows for a plugin:
var data = [{
"label": "Follows",
"color": "#aad874",
"data": [
["Seg", 50],
["Ter", 84],
["Qua", 52],
["Qui", 88],
["Sex", 69],
["Sab", 92],
["Dom", 58]
]
}, {
"label": "UnFollows",
"color": "#7dc7df",
"data": [
["Seg", 13],
["Ter", 44],
["Qua", 44],
["Qui", 27],
["Sex", 38],
["Sab", 11],
["Dom", 39]
]
}];
I have tried several things like:
$staticWeeks = self::statisticstaWeeks();
$staticsDays['Follow'] = [];
$staticsDays['FollowBy'] = [];
if(count($staticWeeks) > 0):
foreach($staticWeeks as $weeks):
array_push($staticsDays['Follow'], $weeks->ins_sta_follow);
array_push($staticsDays['FollowBy'], $weeks->ins_sta_following);
endforeach;
endif;
$staticsDays['Follow'] = $diasFollow = [
"Seg" => (!empty($staticsDays['Follow'][0]) ? $staticsDays['Follow'][0] : 0),
"Ter" => (!empty($staticsDays['Follow'][1]) ? $staticsDays['Follow'][1] : 0),
"Qua" => (!empty($staticsDays['Follow'][2]) ? $staticsDays['Follow'][2] : 0),
"Qui" => (!empty($staticsDays['Follow'][3]) ? $staticsDays['Follow'][3] : 0),
"Sex" => (!empty($staticsDays['Follow'][4]) ? $staticsDays['Follow'][4] : 0),
"Sab" => (!empty($staticsDays['Follow'][5]) ? $staticsDays['Follow'][5] : 0),
"Dom" => (!empty($staticsDays['Follow'][6]) ? $staticsDays['Follow'][6] : 0)];
$staticsDays['FollowBy'] = $diasFollowBy = [
"Seg" => (!empty($staticsDays['FollowBy'][0]) ? $staticsDays['FollowBy'][0] : 0),
"Ter" => (!empty($staticsDays['FollowBy'][1]) ? $staticsDays['FollowBy'][1] : 0),
"Qua" => (!empty($staticsDays['FollowBy'][2]) ? $staticsDays['FollowBy'][2] : 0),
"Qui" => (!empty($staticsDays['FollowBy'][3]) ? $staticsDays['FollowBy'][3] : 0),
"Sex" => (!empty($staticsDays['FollowBy'][4]) ? $staticsDays['FollowBy'][4] : 0),
"Sab" => (!empty($staticsDays['FollowBy'][5]) ? $staticsDays['FollowBy'][5] : 0),
"Dom" => (!empty($staticsDays['FollowBy'][6]) ? $staticsDays['FollowBy'][6] : 0)];
$follow = [(object)[
"label" => "Seguindo",
"color" => "#aad874",
"data" => $staticsDays['Follow']
]];
$followBy = [(object)[
"label" => "Seguidores",
"color" => "#7dc7df",
"data" => $staticsDays['FollowBy']
]];
$result = array_merge($follow, $followBy);
return json_encode( $result );
And yet it does not return as I want.