|
Documentation: scatter.
We set a default dot for scatter charts, just like we did for a normal
line chart.
Each point in a scatter chart requires an X and Y position. There are a number of
options to do this:
- Use any of the classes that inherit from the dot_base
then set the x and y values. Notice how this becomes, annoyingly, 2 lines of code which we can't put in the
array builder. It needs two lines of code because
PHP does not allow us to override the constructor method. So anyway, we use a function (factory) to build the
star object.
- Or use the scatter_value class. Each point
will still inherit all of its attributes from the default dot, this just makes the code clearer to read.
- Or we could code a class that acted like scatter_value but inherited from star (this would be a sugar
class - its only purpose is to make the code look nice)...
The tooltip will convert these magic variables into their real values:
This goes into the <head> of the page:
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF(
"open-flash-chart.swf", "my_chart",
"600", "400", "9.0.0", "expressInstall.swf",
{"data-file":"gallery/scatter-chart.php"} );
</script>
This writes the chart into a div with id="my_chart",
right click and view source to see it in action,
[the tutorials have more details]
gallery/scatter-chart.php
<?php
include '../php-ofc-library/open-flash-chart.php'; // also include the sugar (helper funtions) include '../php-ofc-library/ofc_sugar.php';
function make_star($x, $y) { $tmp = new star(); $tmp->position($x, $y); return $tmp; }
$chart = new open_flash_chart();
$title = new title( date("D M d Y") ); $chart->set_title( $title );
$scatter = new scatter( '#FFD600', 10 ); $scatter->set_default_dot_style( new s_star('#8B1D55', 10) ); $scatter->set_values( array( make_star( 0, 0 ) ) );
$chart->add_element( $scatter );
// // plot a circle // $s2 = new scatter( '#D600FF', 3 ); $s2->set_default_dot_style( new s_box('#D600FF', 4) );
$v = array(); for( $i=0; $i<360; $i+=5 ) { $v[] = new scatter_value( number_format(sin(deg2rad($i)) *.9, 2, '.', ''), number_format(cos(deg2rad($i)) *.9, 2, '.', '') ); } $s2->set_values( $v ); $chart->add_element( $s2 );
$x = new x_axis(); $x->set_range( -1, 1 ); $chart->set_x_axis( $x );
$y = new x_axis(); $y->set_range( -1, 1 ); $chart->add_y_axis( $y );
echo $chart->toPrettyString();
|
Adverts:
|