我想在codeigniter上做一个图表,但我总是失败。请帮助我错误的文本:遇到 PHP 错误
严重性:警告消息:为 foreach() 提供的参数无效 文件名:chart/index.php 块引用行号:16
我的观点 :
<!-- **********************************************************************************************************************************************************
MAIN CONTENT
*********************************************************************************************************************************************************** -->
<!--main content start-->
<section id="main-content">
<section class="wrapper">
<!-- BASIC FORM ELELEMNTS -->
<div class="row mt">
<div class="col-lg-12">
<?php
#periksa array
foreach($data as $data){
$id_reservasi[] = $data->id_reservasi;
$stok[] = (float) $data->stok;
}
?>
</head>
<body>
<canvas id="canvas" width="1000" height="280"></canvas>
<!--Load chart js-->
<script type="text/javascript" src="<?php echo base_url().'assets/chartjs/chart.min.js'?>"></script>
<script>
var lineChartData = {
labels : <?php echo json_encode($id_reservasi);?>,
datasets : [
{
fillColor: "rgba(60,141,188,0.9)",
strokeColor: "rgba(60,141,188,0.8)",
pointColor: "#3b8bba",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(152,235,239,1)",
data : <?php echo json_encode($stok);?>
}
]
}
var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Line(lineChartData);
</script>
</div><!-- /col-lg-4 -->
</div><!-- /row -->
</section>
</section><!-- /MAIN CONTENT -->
我的模型:
function get_chart(){
$query = $this->db->query("SELECT id_reservasi,SUM(status_reservasi) AS stok FROM tbl_reservasi GROUP BY id_reservasi");
if($query->num_rows() > 0){
foreach($query->result() as $data){
$hasil[] = $data;
}
return $hasil;
}
}
我的控制器:
public function chart() {
$x['data']=$this->sistem_model->get_chart();
$this->template_system->load('template_system','sistem/data/chart/index',$x);
}
请给我解决方案...