jpgraph小记


学习php,试着拿php搭个监控界面
画图?rrc?据说jpgraph这玩意儿更好用
官网手册:http://doc.async.com.br/jpgraph/html/index.html

注:安装它需要支持gd2的php,在phpinfo()中查找php.ini
打开extension=php_gd2.dll的选项
在httpd.conf中加入DocumentRoot "/var/www/html"
然后在该目录下建立monitor文件夹
安装完jpgraph,为方便起见,将src文件夹拷到monitor下

Example下有各种示例,慢慢研究下,源代码在src下

index.php的代码
<html><body>
<?php
include ("./log_complete.php");
include ("./job_complete.php");
?>
<table>
  <tr><td><img src="./kk" border=0></td>
  <td><img src="./qq" border=0></td></tr>
<tr><td><center><b>最近<a href="./log_complete.php?idate=<?php echo date('Ymd',strtotime('-1 day'));?>">1</a>
                       <a href="./log_complete.php?idate=<?php echo date('Ymd',strtotime('-2 day'));?>">2</a>
                       <a href="./log_complete.php?idate=<?php echo date('Ymd',strtotime('-3 day'));?>">3</a>
                       <a href="./log_complete.php?idate=<?php echo date('Ymd',strtotime('-4 day'));?>">4</a>
                       <a href="./log_complete.php?idate=<?php echo date('Ymd',strtotime('-5 day'));?>">5</a>
                       <a href="./log_complete.php?idate=<?php echo date('Ymd',strtotime('-6 day'));?>">6</a>
                       <a href="./log_complete.php?idate=<?php echo date('Ymd',strtotime('-7 day'));?>">7</a>天的情况
</b></center></td>
<td><center><b>最近<a href="./job_complete.php?idate=<?php echo date('Ymd',strtotime('-1 day'));?>">1</a>
                       <a href="./job_complete.php?idate=<?php echo date('Ymd',strtotime('-2 day'));?>">2</a>
                       <a href="./job_complete.php?idate=<?php echo date('Ymd',strtotime('-3 day'));?>">3</a>
                       <a href="./job_complete.php?idate=<?php echo date('Ymd',strtotime('-4 day'));?>">4</a>
                       <a href="./job_complete.php?idate=<?php echo date('Ymd',strtotime('-5 day'));?>">5</a>
                       <a href="./job_complete.php?idate=<?php echo date('Ymd',strtotime('-6 day'));?>">6</a>
                       <a href="./job_complete.php?idate=<?php echo date('Ymd',strtotime('-7 day'));?>">7</a>天的情况
</b></center></td></tr>
</table>
</body></html>

log_complete.php:
<?php
include_once("./src/jpgraph.php");
include_once("./src/jpgraph_line.php");
include_once("./src/jpgraph_date.php");
function  TimeCallback($aVal) {
    return date('H:i', $aVal);
}
注意头文件最好都用include_once,否则会出现重复引用的错误,这跟c++倒是很像
TimeCallback是个回调函数,拿来设置x轴坐标格式的
其余代码可参见Example中的dateaxisex1.php

添加如下几行可达到显示数值、网格的效果,如图所示
$line->mark->SetType(MARK_FILLEDCIRCLE);
$line->mark->SetSize(3);
$line->value ->Show();
$line->value->SetFormat( "%d");
$graph ->xgrid->Show(true);



注意如果用datlin来做坐标的格式,x轴是用时间来表示的,因此如果坐标想要显示从当天0点到24点,坐标起点应为如下
$start = mktime (0,0,0,date("m"),date("d"),date("Y"));
然后每个格子递增3600即可

你可能感兴趣的:(html,C++,c,PHP,C#)