2009年5月24日 星期日

[php] PHP/SWF

一個用來畫圖表(長條圖圓餅圖bla)的元件
很漂亮阿!! 而且整個會動超酷
官方頁面

使用:
include "./chart/charts.php";
echo InsertChart ( "./chart/charts.swf", "./chart/charts_library", "sample.php", 600, 400);
?>


include進來charts.php(函式庫)
然後把想要畫成的檔案寫在sample.php裡面

sample.php:
include "./chart/charts.php";
require("config.php");

$SQL = "SELECT UID, COUNT(UID) AS count FROM `performance` GROUP BY UID ORDER BY COUNT(UID) DESC";
$query = mysql_query($SQL);
$name = array("");
$count = array("performance");
while($result = mysql_fetch_array($query)){
$name[] .= $result['UID'];
$count[] .= $result['count'];
}

//$chart['chart_type']="bar"; //橫條圖
//$chart['chart_data'] = array(array("", "2001", "2002", "2003", "2004"),
// array("Region A", 5, 10, 30, 63),
// array("Region B", 100, 20, 65, 55),
// array("Region C", 56, 21, 5, 90));
$chart['chart_data'] = array($name,$count);

$chart[ 'axis_value' ] = array ( 'min'=>0, 'font'=>"arial", 'bold'=>true, 'size'=>12, 'color'=>"000000", 'alpha'=>50, 'steps'=>4, 'prefix'=>"", 'suffix'=>"", 'decimals'=>0, 'separator'=>"", 'show_min'=>true );

$chart[ 'chart_border' ] = array ( 'color'=>"000000", 'top_thickness'=>1, 'bottom_thickness'=>2, 'left_thickness'=>0, 'right_thickness'=>0 );
//$chart[ 'chart_data' ] = array ( array ( "", "2005", "2006", "2007" ), array ( "region A", -20, 45, 100 ), array ( "region B", -40, 65, 80) );
$chart[ 'chart_grid_h' ] = array ( 'alpha'=>20, 'color'=>"FFFFFF", 'thickness'=>1, 'type'=>"dashed" );
$chart[ 'chart_rect' ] = array ( 'positive_color'=>"3333FF", 'negative_color'=>"FFFFFF", 'positive_alpha'=>30, 'negative_alpha'=>0 );
$chart[ 'chart_transition' ] = array ( 'type'=>"scale", 'delay'=>.5, 'duration'=>3, 'order'=>"series" );
$chart[ 'chart_value' ] = array ( 'color'=>"ffffff", 'alpha'=>85, 'font'=>"arial", 'bold'=>true, 'size'=>15, 'position'=>"top", 'prefix'=>"", 'suffix'=>"", 'decimals'=>0, 'separator'=>"", 'as_percentage'=>false );

$chart[ 'draw' ] = array ( array ( 'type'=>"text", 'color'=>"000000", 'alpha'=>10, 'font'=>"arial", 'rotation'=>-90, 'bold'=>true, 'size'=>75, 'x'=>-20, 'y'=>300, 'width'=>300, 'height'=>200, 'text'=>"performance", 'h_align'=>"left", 'v_align'=>"top" ) );

$chart[ 'legend_label' ] = array ( 'layout'=>"horizontal", 'font'=>"arial", 'bold'=>true, 'size'=>15, 'color'=>"333355", 'alpha'=>90 );
$chart[ 'legend_rect' ] = array ( 'x'=>75, 'y'=>27, 'margin'=>5, 'fill_color'=>"000066", 'fill_alpha'=>0, 'line_color'=>"000000", 'line_alpha'=>0, 'line_thickness'=>0 );

$chart[ 'series_color' ] = array ("666666"); // 長條的顏色
$chart[ 'series_gap' ] = array ( 'set_gap'=>40, 'bar_gap'=>-25 );

SendChartData ( $chart );

?>

這樣就有美美的圖了 驚!
不過按下圖後會自動連到首頁
要license才可以作圖的互動 可惜阿

沒有留言:

張貼留言