php与Open Flash Chart多报表切换例子

Open Flash Chart多报表我们在许多的网站都会看到这个功能了,今天小编就来为各位介绍Open Flash Chart多报表使用方法吧,将生成好的JSON数据传递给前端,前端通过JS来实现切换效果,例子.

  1. <?php
  2. //
  3. // This is the MODEL section:
  4. //
  5. <a href="/tags.php/include/" target="_blank">include</a> '../php-ofc-library/open-flash-chart.php';
  6. $title = new title( date("D M d Y") );
  7. $bar = new bar();
  8. $bar->set_values( array(9,8,7,6,5,4,3,2,1) );
  9. $chart_1 = new open_flash_chart();
  10. $chart_1->set_title( $title );
  11. $chart_1->add_element( $bar );
  12. // generate some random data
  13. srand((double)microtime()*1000000);
  14. $tmp = array();
  15. for( $i=0; $i<9; $i++ )
  16. $tmp[] = rand(1,10);
  17. $bar_2 = new bar();
  18. $bar_2->set_values( $tmp );
  19. $chart_2 = new open_flash_chart();
  20. $chart_2->set_title( new title( "Chart 2 :-)" ) );
  21. $chart_2->add_element( $bar_2 );
  22. //
  23. // This is the VIEW section:
  24. //
  25. ?>
  26. <html>
  27. <head>
  28. <script type="text/<a href="/js_a/js.html" target="_blank">javascript</a>" src="js/json/json2.js"></script>
  29. <script type="text/javascript" src="js/swfobject.js"></script>
  30. <script type="text/javascript">
  31. swfobject.embedSWF("open-flash-chart.swf", "my_chart", "350", "200", "9.0.0");
  32. </script>
  33. <script type="text/javascript">
  34. function ofc_ready()
  35. {
  36. alert('ofc_ready');
  37. }
  38. function open_flash_chart_data()
  39. {
  40. alert( 'reading data' );
  41. return JSON.stringify(data_1);
  42. }
  43. function load_1()
  44. {
  45. tmp = findSWF("my_chart");
  46. x = tmp.load( JSON.stringify(data_1) );
  47. }
  48. function load_2()
  49. {
  50. alert("loading data_2");
  51. tmp = findSWF("my_chart");
  52. x = tmp.load( JSON.stringify(data_2) );
  53. }
  54. function findSWF(movieName) {
  55. if (navigator.appName.indexOf("Microsoft")!= -1) {
  56. return window[movieName];
  57. } else {
  58. return document[movieName];
  59. }
  60. }
  61. var data_1 = <?php echo $chart_1->toPrettyString(); ?>;
  62. var data_2 = <?php echo $chart_2->toPrettyString(); ?>;
  63. </script>
  64. </head>
  65. <body>
  66. <p>Open Flash Chart</p>
  67. //开源软件:phpfensi.com
  68. <div ></div>
  69. <br>
  70. <a href="javascript:load_1()">display data_1</a> || <a href="javascript:load_2()">display data_2</a>
  71. <p>
  72. Don't forget to 'view source' to see how the Javascript JSON data is loaded.
  73. </p>
  74. </body>
  75. </html>