Chart Elements - Y Axis Menu - Y Axis Right
Data from: worldometers
"Tags" has another example of a bar chart with right Y axis.
Object: y_axis_right
Methods:
- set_stroke( $s )
Line width in pixels
- set_tick_length( $val )
- set_colours( $colour, $grid_colour )
- set_colour( $colour )
- set_grid_colour( $colour )
- set_range( $min, $max, $steps=1 )
Set min and max values, also (optionally) set the steps value.
- set_offset( $off )
$off: Boolean. If true the Y axis is nudged up half a step.
- set_labels( $labels )
An array of string values. By default the Y axis will show from min to max, but
you can override this by passing in your own labels. Remember the Y axis min is
at the bottom, so the labels will go from bottom to top.
- set_steps( $steps )
Only show every $steps label
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", "350", "9.0.0", "expressInstall.swf",
{"data-file":"gallery/y-axis-right.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/y-axis-right.php
<?php
include '../php-ofc-library/open-flash-chart.php';
$title = new title( "Number of cars produced (millions)" ); $title->set_style( "{font-size: 20px; font-weight: bold; color: #172229; text-align: center;}" );
$vals = array(); $x_labels = array();
$x_labels[] = '1999'; $vals[] = 39.759847; $x_labels[] = '2000'; $vals[] = 41.215653; $x_labels[] = '2001'; $vals[] = 39.825888; $x_labels[] = '2002'; $vals[] = 41.358394; $x_labels[] = '2003'; $vals[] = 41.968666; $x_labels[] = '2004'; $vals[] = 44.554268; $x_labels[] = '2005'; $vals[] = 46.862978; $x_labels[] = '2006'; $vals[] = 49.886549; $x_labels[] = '2007'; $vals[] = 54.920317; $x_labels[] = '2008'; $vals[] = 52.940559; $x_labels[] = '2009'; $vals[] = 51.971328;
$d = new hollow_dot(); $d->size(4)->halo_size(0)->colour('#3D5C56');
$line = new line(); $line->set_default_dot_style($d); $line->set_colour('#3D5C56'); $line->set_values( $vals ); $line->attach_to_right_y_axis();
$chart = new open_flash_chart(); $chart->set_title( $title ); $chart->add_element( $line );
// // create a Y Axis object // $y = new y_axis_right(); // these number crash the chart :-( //$y->set_range( 35000000, 52000000, 1000000 ); $y->set_range( 35, 55, 5 ); $y->set_stroke( 3 ); $y->set_colour( '#3D5C56' ); $y->set_tick_length( 12 ); $y->set_steps( 2 ); // $y->set_labels( array('Zero','One','Two','Three','Four','Five','Six','Seven','Eight') );
// // Add the Y Axis object to the chart: // $chart->set_y_axis_right( $y ); //
$x = new x_axis(); $x->set_labels_from_array($x_labels); $chart->set_x_axis( $x );
echo $chart->toPrettyString();
|
|