我有以下控制器将数据从mysql数据库传递到json
function chart_js() {
$rows = '';
$query = "SELECT clnt_id,date_added FROM job_card ORDER BY date_added DESC LIMIT 0, 5";
$result = $this->db->query($query);
$total_rows = $result->num_rows;
if ($result) {
$rows = $result->result_array();
}
echo json_encode($rows);
}
该数据应该用于使用morris.js在我的视图上绘制/绘制线图。以下是我的脚本和HTML代码:
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-bar-chart-o fa-fw"></i> Client Jobs Past 7 days
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div id="acctregs" style="height: 300px;"></div>
</div>
<!-- /.panel-body -->
</div>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
<script>
var acct_regs = "<?php echo base_url(); ?>/operations/chart_js";
var acctregs = new Morris.Line({
// ID of the element in which to draw the chart.
element: 'acctregs',
// Chart data records -- each entry in this array corresponds to a point on
// the chart.
data: acct_regs,
// The name of the data record attribute that contains x-values.
xkey: 'date_added',
// A list of names of data record attributes that contain y-values.
ykeys: ['clnt_id'],
// Labels for the ykeys -- will be displayed when you hover over the
// chart.
labels: ['Value'],
dateFormat: function (x) {
return new Date(x).toString().split("00:00:00")[0];
}
});
</script>
应该从上面提到的函数chart_js获取数据并使用它来绘制图形。但我不断收到错误:
TypeError: a is undefined
...,h,i,j,k,l;return"number"==typeof a?a:(c=a.match(/^(\d+) Q(\d)$/),e=a.match(/^(\...
问题在于用于从数据库获取数据的url,因为当我使用静态数据时,它的工作原理是什么,传递这个url的方法是什么:
var acct_regs = "<?php echo base_url(); ?>/operations/chart_js";