我想将我从数据库中获取的数据放入Fusionchart JSON(即堆叠类型图表)中。我想将变量$ data放入类别而不是类别。
我尝试使用推数组,但数据不在应有的位置,
$charts = array(
'chart' =>
array(
'caption' => 'Sales Performance Indicator',
'subcaption' => 'By Plan & Achievement',
'numvisibleplot' => '6',
'showvalues' => '1',
'decimals' => '1',
'stack100percent' => '1',
'valuefontcolor' => '#FFFFFF',
'plottooltext' => '$label has $dataValue ($percentValue)
$seriesName sales product',
'theme' => 'zune',
),
'categories' =>
array(
array(
'category' =>
array(
0 =>
array (
'label' => 'Farid',
),
1 =>
array (
'label' => 'Erna',
),
2 =>
array (
'label' => 'Dudi',
),
3 =>
array (
'label' => 'Yudha',
),
4 =>
array (
'label' => 'Ahmad',
),
)
)
),
foreach ($query->result() as $val) {
$data = array('label' => $val->name);
$charts["categories"][] = $data;
}
请帮助
答案 0 :(得分:0)
这不是一个完美的方法。但这起作用吗?
$charts = array(
'chart' =>
array(
'caption' => 'Sales Performance Indicator',
'subcaption' => 'By Plan & Achievement',
'numvisibleplot' => '6',
'showvalues' => '1',
'decimals' => '1',
'stack100percent' => '1',
'valuefontcolor' => '#FFFFFF',
'plottooltext' => '$label has $dataValue ($percentValue)
$seriesName sales product',
'theme' => 'zune',
),
'categories' =>
array(
array(
'category' =>
array(
0 =>
array (
'label' => 'Farid',
),
1 =>
array (
'label' => 'Erna',
),
2 =>
array (
'label' => 'Dudi',
),
3 =>
array (
'label' => 'Yudha',
),
4 =>
array (
'label' => 'Ahmad',
),
)
)
),
);
$data = array(
"stuff" => 1,
"items" => 2,
);
array_push($charts['categories'][0]['category'], $data);
print_r($charts);