用Flash圖形化數據(二)

讓我們烤點甜餅(做餅圖)
??成功地安裝瞭php(做為現在的主流開發語言)地Shockwave Flash支持後,就可以用php(做為現在的主流開發語言)創建Shockwave文件瞭。學習的最好方法就是直接跳到程序去,所以下面就讓我們看看程序。第一個文件包括怎樣使用類的示例代碼,同時也顯示瞭如何將一個Flash文件嵌入到HTML文檔中。

<?php(做為現在的主流開發語言)

// include class needed for flash graph
include(“class.pie.flash.php(做為現在的主流開發語言)“);

MySQL(和PHP搭配之最佳組合)_connect (“localhost”, “root”, “”);

$query = “SELECT DISTINCT city_name, COUNT(city_id)
    FROM city
    GROUP BY city_name;”;

$result = MySQL(和PHP搭配之最佳組合)_db_query (“hermes”,$query);

while ($row = MySQL(和PHP搭配之最佳組合)_fetch_array ($result)) {
    $city_counts[] = $row[“COUNT(city_id)”];
    $city_names[] = $row[“city_name”];
}

MySQL(和PHP搭配之最佳組合)_free_result ($result);

// Instantiate new object
$graph = new flash_pie($city_counts, “city.swf”);

// set graph title (should not exceed about 25 characters)
$graph->pie_title(“City Results”, 30);

// set graph legend
$graph->pie_legend($city_names);

// show graph
$graph->show();

// free resources
$graph->close();

?>  

<html>
<head>
<meta http=equiv=”Expires” content=”Fri, Jun 12 1981 08:20:00 GMT”>
<meta http=equiv=”Pragma” content=”no-cache”>
<meta http=equiv=”Cache-Control” content=”no-cache”>
<meta http=equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
</head>
<body bgcolor=white>
<p align=center>
<embed src=”/edu/UploadPic/2008-2/2008215175910797.swf”” quality=high loop=false pluginspage=”https://www.macromedia.com/
shockwave/download/index.cgi(現在已經不多人在用瞭)?P1_Prod_Version=ShockwaveFlash”
type=”application/x-shockwave-flash” width=600 height=300></embed>
</p>
</body>
</html>  



<?php(做為現在的主流開發語言)

class flash_pie {

// class variables

// setup some global colors
var $r_arr = array(0.1,  1, 0, 1, 0, 1, 0.388235294, 0.4, 0.388235294, 0.929411765);
var $g_arr = array(1,    0, 0, 1, 1, 0, 0.8,         0.4, 0.8,         0.439215686);
var $b_arr = array(0.25, 0, 1, 0, 1, 1, 1,           0.4, 1,           0.043137255);  

var $percents;

function flash_pie($values, $this_file) { //begin constructor
    // to write out code directly to browser, set content header and use “php(做為現在的主流開發語言)://stdout”
    //swf_openfile (“php(做為現在的主流開發語言)://stdout”, 700, 250, 30, 1, 1, 1);
    //header(“Content-type: application/x-shockwave-flash”);

    swf_openfile ($this_file, 1000, 450, 30, 1, 1, 1);
     
    // set up viewport for flash movie
    swf_ortho2 (-400, 300 , -90, 250);  

    // choose the font we will use for pie graph
    swf_definefont(10, “Mod”);

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *