hello World,
i would like to know how to incorporate chart views into Cakehp 3,
this is a sample chart link http://gionkunz.github.io/chartist-js/
my apologies first as i don’t know what to show from the controller or template as hope that someone can show some ropes of what are the steps i need to prepare
i got an Orders Controller which recorded transactions, from there how can i start to dig on?
$series = $this->Orders->find('list', [
'keyField' => 'month',
'valueField' => 'price',
'fields'=>[
'month' => 'MONTHNAME(created_at)',
'price' => 'SUM(price)'
],
'group' => ['month'],
'order'=>['MONTHNAME(created_at)'=>'ASC'],
])
->where(['user_id' => $this->authUser['id']])
->toArray();
$months = json_encode(array_keys($series));
$amounts = json_encode(array_values($series));
$this->set('months', $months);
$this->set('amounts', $amounts);
$this->set(compact('series'));
The View Page to show dynamic chart how am i going to do the setting?
view.ctp
<div class="widget-content tab-content bg-white p-20">
<div class="ct-chart tab-pane active" id="scoreLineToDay"></div>
<script>
new Chartist.Line('.ct-chart', {
labels: [<?= json_encode($months) ?>],
series: [
[<?= json_encode($amounts) ?>]
]
}, {
low: 0,
showArea: true
});
</script>
<div class="ct-chart tab-pane" id="scoreLineToWeek"></div>
<div class="ct-chart tab-pane" id="scoreLineToMonth"></div>
i added the script in the view.ctp in the way, is this correct? as the view is not showing the updated chart…