scatter-chart.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * PHP Integration of Open Flash Chart
  4. * Copyright (C) 2008 John Glazebrook <open-flash-chart@teethgrinder.co.uk>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. require_once('OFC/OFC_Chart.php');
  21. $chart = new OFC_Chart();
  22. $title = new OFC_Elements_Title( date("D M d Y") );
  23. $chart->set_title( $title );
  24. $scatter = new OFC_Charts_Scatter( '#FFD600', 10 );
  25. $scatter->set_values(
  26. array(
  27. new OFC_Charts_Scatter_Value( 0, 0 )
  28. )
  29. );
  30. $chart->add_element( $scatter );
  31. //
  32. // plot a circle
  33. //
  34. $s2 = new OFC_Charts_Scatter( '#D600FF', 3 );
  35. $v = array();
  36. for( $i=0; $i<360; $i+=5 )
  37. {
  38. $v[] = new OFC_Charts_Scatter_Value(
  39. number_format(sin(deg2rad($i)), 2, '.', ''),
  40. number_format(cos(deg2rad($i)), 2, '.', '') );
  41. }
  42. $s2->set_values( $v );
  43. $chart->add_element( $s2 );
  44. $x = new OFC_Elements_Axis_X();
  45. $x->set_range( -2, 2 );
  46. $chart->set_x_axis( $x );
  47. $y = new OFC_Elements_Axis_Y();
  48. $y->set_range( -2, 2 );
  49. $chart->add_y_axis( $y );
  50. echo $chart->toPrettyString();