Warning this is an old version.

Take me to the latest version

Charts - Pie Charts - Pie Chart

Make a pie chart.

Object: pie()

  • set_values( $v )
    An array of values. Each value can be a number or a pie_value().
  • set_animate( $animate )
    Boolean, true or false
  • set_start_angle( $angle )
    The angle of the first slice
  • set_tooltip( $tip )

    The tooltip text can contain these magic variables, they are replaced with

    • #val# - the number value of the slice
    • #total# - the total of all the slices
    • #percent# - the value as a percent
    • #label# - if you have passed in a label, the tooltip can contain it. This is useful if you set 'nolabel' to true, the pie chart will fill the area, but you can still display a unique label for each slice.

Object: pie_value( $value, $label )

  • set_colour( $colour )
  • set_label( $label, $label_colour, $font_size )

Note: see the advanced pie chart tutorial on how to customize individual pie slices, change fonts, alter colours and add gradient colours.

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.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.php
<?php

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

$title = new title'Pork Pie, Mmmmm' );

$pie = new pie();
$pie->set_start_angle35 );
$pie->set_animatetrue );
$pie->set_tooltip'#val# of #total#<br>#percent# of 100%' );
$pie->set_values( array(2,3,new pie_value(6.5"hello (6.5)")) );

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


$chart->x_axis null;

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


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