open-flash-chart2系列教程(2)–PHP类库的用法
2010-01-30 文章来源:互联网 浏览次数:71
上一章讲了用json,这一章告诉大家open flash chart 提供的PHP类库的用法。
html文章还是用上一章的,data.json.php如下:
- <?php
- require_once('php-ofc-library/open-flash-chart.php');
- $tmpx = array("January","February","March","April","May","June","July","August","Spetember","October","November","December");//x轴标签的数组
- $tmpy1 = array(6,7,9,5,7,6,9,7,3,13,12,16);//从数据库查询得到y轴数据的数组
- $tmpy2 = array(9,6,7,9,5,7,6,9,7,10.5,13.8,15);//从数据库查询得到y轴数据的数组
- #设置标题
- $title = new title( '上传下载统计报表' );
- $title->set_style("{font-size: 20px; color:#000000; font-family: Verdana; text-align: center;}");
- #新建第一个bar
- $bar1 = new bar_glass();
- $bar1->text= "上传";
- //$bar1->set_key('上传', "10");这样的还能加font-size:10;
- $bar1->set_alpha("0.8");
- $bar1->set_colour("#4BB2C5");
- $bar1->set_values( $tmpy1 );
- #新建第二个bar
- $bar2 = new bar_glass();
- $bar2->text= "下载";
- $bar2->set_alpha("0.8");
- $bar2->set_colour("#CC9933");
- $bar2->set_values( $tmpy2 );
- #生成X轴
- $x = new x_axis();
- $x->set_stroke("2");
- $x->set_tick_height("3");
- $x->set_colour("#999999");
- $x->set_grid_colour("#CCCCCC");
- $x->set_labels_from_array( $tmpx );
- #生成Y轴
- $y = new y_axis();
- $y->set_stroke("2");
- $y->set_tick_length("3");
- $y->set_colour("#999999");
- $y->set_grid_colour("#CCCCCC");
- $y->set_offset("0");
- $y->set_range(0,20);
- #生成Y轴
- $yl = new y_legend();
- $yl->y_legend( "Upload And Download" );
- $yl->set_style( "{color: #736AFF; font-size: 12px;}" );
- $chart = new open_flash_chart();
- $chart->set_title( $title );
- $chart->set_y_axis( $y );
- $chart->set_x_axis( $x );
- $chart->set_y_legend( $yl );
- $chart->add_element($bar1);
- $chart->add_element($bar2);
- //echo "<pre>";
- //echo $chart->toPrettyString();
- //echo "</pre>";
- echo $chart->toString();
- ?>
这个PHP文件将生成和上一章data.txt一摸一样的json数据,地址栏输入:http://localhost/open-flash-chart/chart.html?ofc=data.json.php即可

文章评论(查看全部)