统计报表图实现 open flash chart OFC

1629阅读 0评论2010-09-09 dongyue91
分类:系统运维

一,HTML页面JS方式简单调用
    这里只是做一个简单的调用和少量的说明.等以后慢慢玩多玩转了,再补充文章. ^_^

使用URL调用:

xx.html?ofc=data.php


HTML页面[xx.html]

<html>
<head>
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF("open-flash-chart.swf", "my_chart", "1000", "400", "9.0.0");
</script>
</head>
<body>
<div id="my_chart"></div>
</body>
</html>


PHP数据[data.php]

<?php
srand((double)microtime()*1000000);
$data = array();
$now = time();

$dblink = MG::__new('db', $GLOBALS['dbSet']['datareport']);

$date_num = date('t', $now);

for( $i=1; $i<=$date_num; $i++ )
{
    $day = strlen($i) == 1 ? "0$i" : $i;
    $temp = $dblink -> Query("SELECT count(id) AS num FROM t_log_".date("Ym").$day);
    //echo "SELECT count(id) AS num FROM t_log_".date("Y-m").$day;

    $data[] = intval($temp['num']);
    unset($temp);
    $date_day[] = "D:$i";
}

//OFC_CHARTS define的一个路径
require_once(OFC_CHARTS.'php5-ofc-library/lib/OFC/OFC_Chart.php');

$title = new OFC_Elements_Title( date("Y-m") );

$bar = new OFC_Charts_Bar_3d();
$bar->set_values( $data );
$bar->colour = '#B452CD';

$x_axis = new OFC_Elements_Axis_X();
$x_axis -> set_3d(1);
$x_axis -> colour = '#ADFF2F';

//用数组设定X轴下标内容
$x_axis -> set_labels_from_array($date_day);

$y_axis = new OFC_Elements_Axis_Y();
$y_axis -> set_colour('#ADFF2F');
$y_axis -> set_tick_length(5);

//设置Y轴区间及步长
$y_axis -> set_range(0, 500000, 50000);

$chart = new OFC_Chart();
$chart -> set_title($title);
$chart -> add_element($bar);
$chart -> set_x_axis($x_axis);
$chart -> set_y_axis($y_axis);

echo $chart->toPrettyString();
exit;
?>



上一篇:用tail命令及时查看文件变化
下一篇:字符串截取函数