Charts - Pie Charts - Advanced Pie Chart 2

See pie charts and advanced pie chart tutorial for more details.

In this pie chart we have used pie_value( $value, $label ) to set the value and label for each slice. We then turn the labels off but still use them in the tooltip.

Doing this means your pie charts won't be resized to fit the labels on the screen. This may be worth doing if you have many pie charts that need to be the same size.

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-no-labels.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/pie-chart-no-labels.php
<?php

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

$d = array();
$d[] = new pie_value(120"Income");
$d[] = new pie_value(99"Spend");
$d[] = new pie_value(21"Profit");

$pie = new pie();
$pie->set_animatetrue );
//$pie->add_animation( new pie_fade() );
$pie->set_label_colour'#432BAF' );
$pie->set_alpha0.75 );
//
// This is where we turn of the labels,
// but we use them inside the tooltip:
//
$pie->set_tooltip'#label#<br>$#val# (#percent#)' );
$pie->set_no_labels();
//
//
//
$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-no-labels.php, then 'view source'.
Support This Project
Adverts:


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