用Flash图形化数据(二),用Flash图形化数据(二)
【 tulaoshi.com - PHP 】
让我们烤点甜饼(做饼图)
成功地安装了PHP地Shockwave Flash支持后,就可以用PHP创建Shockwave文件了。学习的最好方法就是直接跳到程序去,所以下面就让我们看看程序。第一个文件包括怎样使用类的示例代码,同时也显示了如何将一个Flash文件嵌入到HTML文档中。
<?php
// include class needed for flash graph
include("class.pie.flash.php");
mysql_connect ("localhost", "root", "");
$query = "SELECT DISTINCT city_name, COUNT(city_id)
FROM city
GROUP BY city_name;";
$result = mysql_db_query ("hermes",$query);
while ($row = mysql_fetch_array ($result)) {
$city_counts[] = $row["COUNT(city_id)"];
$city_names[] = $row["city_name"];
}
mysql_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"
<body bgcolor=white
<div align=center
<embed src="http://img.tulaoshi.com/attachment/portal/jcwcj/2005-12/10/05121010212229426.swf"" quality=high loop=false pluginspage="http://www.macromedia.com/
shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"
type="application/x-shockwave-flash" width=600 height=300
<?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");
// get sum of array for percents/slices
while(list($key,$val) = each($values)) {
$sum = $sum + $val;
}
for ($i=0; $i<count($values); $i++) {
// calculate how big they need to be and then
&n
来源:http://www.tulaoshi.com/n/20160129/1493699.html
看过《用Flash图形化数据(二)》的人还看了以下文章 更多>>