1 回答
TA贡献1802条经验 获得超4个赞
未经测试,但也许你可以尝试这样。您应该使用而不是进行一些片状字符串操作json_encode
<?php
$conn=mysqli_connect("localhost","root","","userchart");
$query= "SELECT * FROM chart";
$result=mysqli_query($conn,$query);
$data=array();
while( $row=mysqli_fetch_array($result) ){
$data[]=array(
'user' => $row['uid'],
'time' => date('i',strtotime( $row['time']) )
);
}
$json=json_encode( $data );
?>
<html>
<head>
<title>CHART USING MORRIS.JS</title>
<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.0/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>
</head>
<body>
<div id="chart" style ="height 250px;"></div>
<script>
<?php
printf('var json=%s;',$json);
?>
new Morris.Line({
element: 'chart',
data:json,
xkey:'user',
ykeys:['time'],
labels:['time']
});
</script>
</body>
</html>
- 1 回答
- 0 关注
- 103 浏览
添加回答
举报