1 回答
TA贡献1853条经验 获得超9个赞
首先,您需要从控制器调用模型函数“chart_data”,例如:
$chart_data= $this->model_name->chart_data();
然后将 $chart_data 变量发送到您的视图,如下所示:
$this->load->view('your view name', $chart_data);
之后,您可以在视图中使用 chart_data 变量,如下所示:
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Quality', 'Service', 'Cleanliness', 'Staff'],
datasets: [{
label: 'Average Ratings',
data: ['<?php echo $chart_data['service'] ?>','<?php echo $chart_data['quality'] ?>','<?php echo $chart_data['clean'] ?>','<?php echo $chart_data['staff'] ?>'],
backgroundColor: "rgba(153,255,62,0.6)"
}]},
});
- 1 回答
- 0 关注
- 160 浏览
添加回答
举报