顯示具有 flash 標籤的文章。 顯示所有文章
顯示具有 flash 標籤的文章。 顯示所有文章

2009年5月24日 星期日

[php] Open Flash Chart

其實這篇可以不只是php XD
他還有perl, python, ruby, java, .NET的函式庫可以用 超級強大

Tutorial
Download
真的很強大阿XD

使用:
※OFC 2的版本我怎麼用都不對 怎麼搞都沒有畫面出來阿 囧
所以我就用了1.9.7 這個就夠漂亮夠我用啦~~

<?php
include_once("./open-flash-chart/php-ofc-library/open_flash_chart_object.php");
open_flash_chart_object( 600, 400, './open-flash-chart/chart-data.php', false );
?>


然後在/open-flash-chart裡面 create一個chart-data.php
內容:
<?
$bar = new bar_sketch( 55, 6, '#d070ac', '#000000' );
for( $i=0; $i<count($count); $i++ )
$bar->data[] .= $count[$i];

$g = new graph();
$g->title( 'performance', '{font-size:20px; color: #ffffff; margin:10px; background-color: #d070ac; padding: 5px 15px 5px 15px;}' );
$g->bg_colour = '#FDFDFD';

//
// add the bar object to the graph
//

$g->data_sets[] = $bar;

$g->x_axis_colour( '#e0e0e0', '#e0e0e0' );
$g->set_x_tick_size( 9 );
$g->y_axis_colour( '#e0e0e0', '#e0e0e0' );

$g->set_x_labels( $name );

$g->set_inner_background( '#E3F0FD', '#CBD7E6', 90 );
$g->set_y_max( 10 );
$g->y_label_steps( 2 );
echo $g->render();
?>


$count和$name是從資料庫抓的東西

這樣就好了 一個很可愛的長條圖 我喜歡阿!!

[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才可以作圖的互動 可惜阿