OpenFlashChart使用之线性图表典型使用例子,使用swfobject.js将html图表代码写入到id="my_chart"的DIV中,效果如下:

php中OpenFlashChart使用之线性图表使用例子_flash插件

html代码:

  1. <html>

  2. <head>

  3. <scripttype="text/javascript"src="js/swfobject.js"></script>

  4. <scripttype="text/javascript">

  5. swfobject.embedSWF(

  6. "open-flash-chart.swf", "my_chart",

  7. "600", "350", "9.0.0", "expressInstall.swf",

  8. {"data-file":"gallery/x-legend.php"} );

  9. </script>

  10. </head>

  11. <body>

  12. <p>Hello World</p>

  13. <divid="my_chart"></div>

  14. </body>

  15. </html>

x-legend.php代码如下:

  1. <?php

  2. include'../php-ofc-library/open-flash-chart.php';

  3. $year = array();

  4. $price = array();

  5. $year[] = '1983'; $price[] = 36.7;

  6. $year[] = '1984'; $price[] = 38.7;

  7. $year[] = '1985'; $price[] = 42.8;

  8. $year[] = '1986'; $price[] = 38.2;

  9. $year[] = '1987'; $price[] = 37.8;

  10. $year[] = '1988'; $price[] = 34.7;

  11. $year[] = '1989'; $price[] = 38.4;

  12. $year[] = '1990'; $price[] = 40.2;

  13. $year[] = '1991'; $price[] = 39.5;

  14. $year[] = '1992'; $price[] = 40.3;

  15. $year[] = '1993'; $price[] = 45.9;

  16. $year[] = '1994'; $price[] = 48.9;

  17. $year[] = '1995'; $price[] = 50.9;

  18. $year[] = '1996'; $price[] = 52.9;

  19. $year[] = '1997'; $price[] = 57.9;

  20. $year[] = '1998'; $price[] = 60.9;

  21. $year[] = '1999'; $price[] = 61.9;

  22. $year[] = '2000'; $price[] = 76.9;

  23. $year[] = '2001'; $price[] = 77.9;

  24. $year[] = '2002'; $price[] = 69.9;

  25. $year[] = '2003'; $price[] = 77.9;

  26. $year[] = '2004'; $price[] = 77.9;

  27. $year[] = '2005'; $price[] = 79.9;

  28. $year[] = '2006'; $price[] = 88.9;

  29. $year[] = '2007'; $price[] = 87.9;

  30. $year[] = '2008'; $price[] = 103.9;

  31. $chart = new open_flash_chart();

  32. $title = new title( 'UK Petrol price (pence) per Litre' );

  33. $title->set_style( "{font-size: 20px; color: #A2ACBA; text-align: center;}" );

  34. $chart->set_title( $title );

  35. $area = new area();

  36. $area->set_colour( '#5B56B6' );

  37. $area->set_values( $price );

  38. $area->set_key( 'Price', 12 );

  39. $chart->add_element( $area );

  40. $x_labels = new x_axis_labels();

  41. $x_labels->set_steps( 2 );

  42. $x_labels->set_vertical();

  43. $x_labels->set_colour( '#A2ACBA' );

  44. $x_labels->set_labels( $year );

  45. $x = new x_axis();

  46. $x->set_colour( '#A2ACBA' );

  47. $x->set_grid_colour( '#D7E4A3' );

  48. $x->set_offset( false );

  49. $x->set_steps(4);

  50. // Add the X Axis Labels to the X Axis

  51. $x->set_labels( $x_labels );

  52. $chart->set_x_axis( $x );

  53. //

  54. // LOOK:

  55. //

  56. $x_legend = new x_legend( '1983 to 2008' );

  57. $x_legend->set_style( '{font-size: 20px; color: #778877}' );

  58. $chart->set_x_legend( $x_legend );

  59. //

  60. // remove this when the Y Axis is smarter

  61. //

  62. $y = new y_axis();

  63. $y->set_range( 0, 150, 30 );

  64. $chart->add_y_axis( $y );

  65. echo$chart->toPrettyString();

注意:如果不能正常显示图表请检查 swfobject.js 和x-legend.php的引用路径是否正确(html代码中的 第4行和第10行)