Charts - Pie Charts - Advanced Pie Chart 3

The on-click event can either browse to a new URL or call a Javascript function. The chart figures this out by inspecting the first few characters of the on-click string, if it starts with 'http:' then it browses to the URL, otherwise it tries to call a Javascript function with that name.

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",
"300", "300", "9.0.0", "expressInstall.swf",
{"data-file":"gallery/pie-chart-on-click.php"} );

function pie_slice_clicked( index )
{
alert( 'Pie Slice '+ index +' clicked');
}
</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/pie-chart-on-click.php
<?php

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

$d = array();
$d[] = new pie_value(120"X");
$d[] = new pie_value(99"Y");

//
// override the PIE on-click event:
//
$slice = new pie_value(21"Z");
$slice->on_click('http://example.com');
$d[] = $slice;

$pie = new pie();
$pie->set_animatetrue );
$pie->set_label_colour'#432BAF' );
$pie->set_alpha0.75 );
$pie->set_tooltip'#label#<br>$#val# (#percent#)' );
//
// default on-click event
//
$pie->on_click('pie_slice_clicked');
//
//
//
$pie->set_colours(
    array(
        
'#77CC6D',    // income (green)
        
'#FF5973',    // spend (pink)
        
'#6D86CC'    // profit (blue)
    
) );

$pie->set_values$d );

$chart = new open_flash_chart();
$chart->add_element$pie );

echo 
$chart->toPrettyString();
To see the data produced : gallery/pie-chart-on-click.php, then 'view source'.
Support This Project

Open Flash Chart logo by numb.me.uk. | Syntax highlights are by GeSHi