我有一个图表,我想从存储在模型中的变量中获取值。我的 Jquery 代码:
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: [0,1,2,4,5],
backgroundColor: "rgba(153,255,62,0.6)"
}]},
});
我的型号:
public function chart_data()
{
$total = $this->db->query("SELECT
ROUND(count((service_ans_1)+(service_ans_2)+(service_ans_3)+(quality_ans_1)+(quality_ans_2)+(quality_ans_3)+(quality_ans_4)+(cleanliness_ans_1)+(cleanliness_ans_2)+(cleanliness_ans_3)+(cleanliness_ans_4)+(cleanliness_ans_5)+(staff_ans_1)+(staff_ans_2)+(staff_ans_3))) as total from `dine_in_feedback` as f")->row()->total;
$service = $this->db->query("SELECT
ROUND(avg(((service_ans_1)+(service_ans_2)+(service_ans_3))/3)) as service from `dine_in_feedback` as f")->row()->service;
$quality = $this->db->query("SELECT
ROUND(avg(((quality_ans_1)+(quality_ans_2)+(quality_ans_3)+(quality_ans_4))/4)) as quality from `dine_in_feedback` as f")->row()->quality;
$clean = $this->db->query("SELECT
ROUND(avg(((cleanliness_ans_1)+(cleanliness_ans_2)+(cleanliness_ans_3)+(cleanliness_ans_4)+(cleanliness_ans_5))/5)) as clean from `dine_in_feedback` as f")->row()->clean;
$staff = $this->db->query("SELECT
ROUND(avg(((staff_ans_1)+(staff_ans_2)+(staff_ans_3))/15)) as staff from `dine_in_feedback` as f")->row()->staff;
$result['service'] = $service / $total * 100;
$result['quality'] = $quality / $total * 100;
$result['clean'] = $clean / $total * 100;
$result['staff'] = $staff / $total * 100;
return $result;
}
我想要“数据:[0,1,2,4,5]”中的服务,质量,清洁和员工价值,例如数据:[服务价值,质量价值,清洁价值,员工价值]
暮色呼如