/**
  * Build The Pie Gharph.
  *
  * @param  array  $params  assoc array of name/value pairs          
  *
  * @return object $chart   object of open flash chart.
  * @static
  */
 static function &pieChart(&$params)
 {
     $chart = null;
     if (empty($params)) {
         return $chart;
     }
     $allValues = CRM_Utils_Array::value('values', $params);
     if (!is_array($allValues) || empty($allValues)) {
         return $chart;
     }
     // get the required data.
     $values = array();
     foreach ($allValues as $label => $value) {
         $values[] = new pie_value((double) $value, $label);
     }
     $graphTitle = CRM_Utils_Array::value('legend', $params) ? $params['legend'] : ts('Pie Chart');
     //get the currency.
     require_once 'CRM/Utils/Money.php';
     $config = CRM_Core_Config::singleton();
     $symbol = $config->defaultCurrencySymbol;
     $pie = new pie();
     $pie->radius(100);
     // call user define function to handle on click event.
     if ($onClickFunName = CRM_Utils_Array::value('on_click_fun_name', $params)) {
         $pie->on_click($onClickFunName);
     }
     $pie->set_start_angle(35);
     $pie->add_animation(new pie_fade());
     $pie->add_animation(new pie_bounce(2));
     // set the tooltip.
     $tooltip = CRM_Utils_Array::value('tip', $params, "Amount is {$symbol} #val# of {$symbol} #total# <br>#percent#");
     $pie->set_tooltip($tooltip);
     // set colours.
     $pie->set_colours(self::$_colours);
     $pie->set_values($values);
     //create chart.
     $chart = new open_flash_chart();
     // create chart title obj.
     $title = new title($graphTitle);
     $chart->set_title($title);
     $chart->add_element($pie);
     $chart->x_axis = null;
     return $chart;
 }
示例#2
0
   	$sql = "DELETE FROM cache WHERE name like 'chart_tophosts%' AND updatetime< NOW() - INTERVAL ".$_SESSION['CACHE_CHART_TOPHOSTS']." MINUTE";
   	$result = perform_query($sql, $dbLink, $_SERVER['PHP_SELF']);
	// Set random pie colors
   	for($i = 0; $i<=count($array) ; $i++) {
	$colors[] = '#'.random_hex_color(); // 09B826
	}

   	$pie->set_alpha(0.5);
	$pie->add_animation( new pie_fade() );
	$pie->add_animation( new pie_bounce(5) );
	// $pie->start_angle( 270 )
	$pie->start_angle( 0 );
	$pie->set_tooltip( '#label#<br>#val# of #total#<br>#percent# of top 10 hosts' );
	$pie->radius(80);
	$pie->set_colours( $colors );
    $pie->on_click('pie_slice_clicked');
	$pie->set_values( $array );
	$chart = new open_flash_chart();
	// $chart->set_title( $title );
	$chart->add_element( $pie );
	echo $chart->toPrettyString();
    break;

    case "chart_topmsgs":
        $title = new title( date("D M d Y") );
   	// -------------------------
   	// Get Top 10 Messages
   	// -------------------------
   	$pie = new pie();
   	$sql = "SELECT name, value, updatetime FROM cache WHERE name like 'chart_topmsgs%' AND updatetime> NOW() - INTERVAL ".$_SESSION['CACHE_CHART_TOPMSGS']." MINUTE";
   	$result = perform_query($sql, $dbLink, $_SERVER['PHP_SELF']);