Examples

All these examples are from teethgrinder.co.uk. Visit the page, it hosts even some more examples and tutorials.


This is the code that was used to generate the $chart object which we passed to this view:

  1.  <?php
  2.   
  3.  $title = new title( 'Pork Pie, Mmmmm' );
  4.   
  5.  $d = array();
  6.  $d[] = 2;        // <-- blue
  7.  $d[] = 3;        // <-- grey
  8.  $d[] = 4;        // <-- green
  9.  $tmp = new pie_value(6.5, "");
  10.  //
  11.  // this slice would normally be light green
  12.  // but we are overriding the colour here:
  13.  //
  14.  $tmp->set_colour( '#FF33C9' );
  15.  $tmp->set_label('BIG', '#FF653F', 24 );
  16.  $d[] = $tmp;
  17.  //
  18.  // here the colour cycle wraps and this gets the
  19.  // first colour:
  20.  //
  21.  $d[] = new pie_value(6.5, "6.5");    // <-- blue
  22.  $d[] = 3;        // <-- grey
  23.  $d[] = 4;        // <-- green
  24.  $d[] = 2;        // <-- light green
  25.   
  26.  $pie = new pie();
  27.  $pie->start_angle(35)
  28.      ->add_animation( new pie_fade() )
  29.      ->add_animation( new pie_bounce(4) )
  30.      // ->label_colour('#432BAF') // <-- uncomment to see all labels set to blue
  31.      ->gradient_fill()
  32.      ->tooltip( '#val# of #total#<br>#percent# of 100%' )
  33.      ->colours(
  34.          array(
  35.              '#1F8FA1',    // <-- blue
  36.              '#848484',    // <-- grey
  37.              '#CACFBE',    // <-- green
  38.              '#DEF799'    // <-- light green
  39.          ) );
  40.   
  41.  $pie->set_values( $d );
  42.   
  43.  $chart = new open_flash_chart();
  44.  $chart->set_title( $title );
  45.  $chart->add_element( $pie );
  46.   
  47.  return $chart;

This view uses the following code to render the graph:

  1.   
  2.  $this->widget(
  3.    'application.extensions.OpenFlashChart2Widget.OpenFlashChart2Widget',
  4.    array(
  5.      'chart' => $chart,
  6.      'width' => '100%'
  7.    )
  8.  );