您的位置主页 > 编程专区 > Php > open-flash-chart2系列教程(2)–PHP类库的用法

open-flash-chart2系列教程(2)–PHP类库的用法

2010-01-30    文章来源:互联网    浏览次数:435

上一章讲了用json,这一章告诉大家open flash chart 提供的PHP类库的用法。

html文章还是用上一章的,data.json.php如下:

 
  1. <?php
  2. require_once('php-ofc-library/open-flash-chart.php');
  3. $tmpx = array("January","February","March","April","May","June","July","August","Spetember","October","November","December");//x轴标签的数组
  4. $tmpy1 = array(6,7,9,5,7,6,9,7,3,13,12,16);//从数据库查询得到y轴数据的数组
  5. $tmpy2 = array(9,6,7,9,5,7,6,9,7,10.5,13.8,15);//从数据库查询得到y轴数据的数组
  6. #设置标题
  7. $title = new title( '上传下载统计报表' );
  8. $title->set_style("{font-size: 20px; color:#000000; font-family: Verdana; text-align: center;}");
  9. #新建第一个bar
  10. $bar1 = new bar_glass();
  11. $bar1->text= "上传";
  12. //$bar1->set_key('上传', "10");这样的还能加font-size:10;
  13. $bar1->set_alpha("0.8");
  14. $bar1->set_colour("#4BB2C5");
  15. $bar1->set_values( $tmpy1 );
  16.  
  17. #新建第二个bar
  18. $bar2 = new bar_glass();
  19. $bar2->text= "下载";
  20. $bar2->set_alpha("0.8");
  21. $bar2->set_colour("#CC9933");
  22. $bar2->set_values( $tmpy2 );
  23.  
  24. #生成X轴
  25. $x = new x_axis();
  26. $x->set_stroke("2");
  27. $x->set_tick_height("3");
  28. $x->set_colour("#999999");
  29. $x->set_grid_colour("#CCCCCC");
  30. $x->set_labels_from_array( $tmpx );
  31. #生成Y轴
  32. $y = new y_axis();
  33. $y->set_stroke("2");
  34. $y->set_tick_length("3");
  35. $y->set_colour("#999999");
  36. $y->set_grid_colour("#CCCCCC");
  37. $y->set_offset("0");
  38. $y->set_range(0,20);
  39. #生成Y轴
  40. $yl =  new y_legend();
  41. $yl->y_legend( "Upload And Download" );
  42. $yl->set_style( "{color: #736AFF; font-size: 12px;}" );
  43.  
  44. $chart = new open_flash_chart();
  45. $chart->set_title( $title );
  46.  
  47. $chart->set_y_axis( $y );
  48. $chart->set_x_axis( $x );
  49. $chart->set_y_legend( $yl );
  50.  
  51. $chart->add_element($bar1);
  52. $chart->add_element($bar2);
  53. //echo "<pre>";
  54. //echo $chart->toPrettyString();
  55. //echo "</pre>";
  56. echo $chart->toString();
  57.  
  58. ?>

这个PHP文件将生成和上一章data.txt一摸一样的json数据,地址栏输入:http://localhost/open-flash-chart/chart.html?ofc=data.json.php即可

文章评论(查看全部)

验证码: 中评 好评 差评