Я хочу отобразить данные из базы данных на myFusionCharts в laravel, но я как-то застрял.Я не могу найти ответы из документации, так как они используют предопределенный набор данных в своем образце.
Любая помощь будет принята с благодарностью.
Это мой контроллер:
public function index()
{
$subj = DB::Table('tbl_subjects')
->select('subject')
->get();
// ->toArray()
foreach ( $subj as $s){
// $c = $s->subject;
$c[] = DB::table('tbl_ordinances')
->where('subject', 'like', '%'.$s->subject.'%')
->get()
->count();
}
// dd($subj,$c);
return view('statistics',compact('subj','c'));
}
I "dd ($ subj, $ c);" и он возвращает следующие значения:
Collection {#302 ▼
#items: array:9 [▼
0 => {#309 ▼
+"subject": "Peace & Order and Public Safety"
}
1 => {#311 ▼
+"subject": "Infrastructure"
}
2 => {#312 ▼
+"subject": "Livelihood/ Poverty Reduction"
}
3 => {#313 ▼
+"subject": "Finance/ Investment"
}
4 => {#314 ▼
+"subject": "Administrative Development"
}
5 => {#315 ▼
+"subject": "Agricultural Development"
}
6 => {#316 ▼
+"subject": "Social Services"
}
7 => {#317 ▼
+"subject": "Environment and Disaster Management"
}
8 => {#318 ▼
+"subject": "Tourism"
}
]
}
array:9 [▼
0 => 2
1 => 0
2 => 0
3 => 0
4 => 4
5 => 0
6 => 3
7 => 6
8 => 1
]
Это мой клинок:
<script type="text/javascript">
FusionCharts.ready(function() {
var revenueChart = new FusionCharts({
type: 'pie2d',
renderAt: 'chart-container',
width: '500',
height: '500',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "Municipal Ordinances by subject categories",
// "subCaption": "Last year",
"numberPrefix": null,
"showPercentInTooltip": "1",
"decimals": "1",
"theme": "fusion",
},
"data": [ // I want THOSE VALUES HERE... but I don't know how..
{"label": "h","value": "25" },
{"label": "h2","value": "25"},
{"label": "h3","value": "55"},
]
}
}).render();
});
</script>
<div id="chart-container">FusionCharts will render here..</div>