软件下载: http://www.hcharts.cn/resource/Highcharts-4.0.1.zip 解压到nginx 的工作目录下,例如:tar xfHighcharts-4.0.1.zip -C /usr/local/nginx/html/ cd/usr/local/nginx/html/picture/Highcharts-4.0.1 首先可以打开 http://localhost/Highcharts-4
软件下载:
http://www.hcharts.cn/resource/Highcharts-4.0.1.zip
解压到nginx 的工作目录下,例如:tar xf Highcharts-4.0.1.zip -C /usr/local/nginx/html/
cd /usr/local/nginx/html/picture/Highcharts-4.0.1
首先可以打开 http://localhost/Highcharts-4.0.1/index.html
查看示例图,根据需求,可以 从 /usr/local/nginx/html/picture/Highcharts-4.0.1/examples 目录下
找到合适自己的模板,然后修改,并完成自己的图表。
mysql> SELECT day,count(id) from logstg group by day;
+------------+-----------+
| day | count(id) |
+------------+-----------+
| 2014-09-09 | 1 |
| 2014-09-10 | 3 |
| 2014-09-11 | 3 |
| 2014-09-12 | 6 |
| 2014-09-15 | 2 |
| 2014-09-16 | 5 |
| 2014-09-17 | 6 |
| 2014-09-18 | 4 |
| 2014-09-19 | 3 |
| 2014-09-22 | 1 |
此处 我需要完成的是php代码从数据库中获取到每天网站的数据,其中day 作为横坐标轴,count(id)作为纵坐标轴。
1.php获取数据 自己 根据这段代码 测试 是否可以正常获取数据。
$con = mysql_connect('172.16.4.134','mysql','homelink');
mysql_select_db("logdb", $con);
$sql = "SELECT day,count(id) from logstg group by day;";
$result=mysql_query($sql,$con);
while($row = mysql_fetch_array($result))
{
$day[]=$row['day'];
$count[]=intval($row['count(id)']);
}
$day = json_encode($day);
print_r($day);
$data1 = array(array("name"=>"count","data"=>$count));
$data1 = json_encode($data1); //把获取的数据对象转换成json格式
print "
$data1";
?>
2.测试完成后,完成下面代码mypic.html。
3.然后就可以访问了。 http://localhost/Highcharts-4.0.1/mypic.html
$con = mysql_connect('172.16.4.134','mysql','homelink');
mysql_select_db("logdb", $con);
$sql = "SELECT day,count(id) from logstg group by day;";
$result=mysql_query($sql,$con);
while($row = mysql_fetch_array($result))
{
$day[]=$row['day'];
$count[]=intval($row['count(id)']);
}
$day = json_encode($day);
$data1 = array(array("name"=>"count","data"=>$count));
$data1 = json_encode($data1); //把获取的数据对象转换成json格式
?>