|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
大部分语言的基础,不是说c有多好,而是c相对起手容易学,让你认为这个是编程语言,饼图|掌握 //挪用办法:<image src="chart.php">
//chart.php为本文文件名
<?
/*
把角度转换为弧度
*/
function radians ($degrees)
{
return($degrees * (pi()/180.0));
}
/*
** 获得在圆心为(0,0)圆上 x,y点的值
*/
function circle_point($degrees, $diameter)
{
$x = cos(radians($degrees)) * ($diameter/2);
$y = sin(radians($degrees)) * ($diameter/2);
return (array($x, $y));
}
// 填充图表的参数
$ChartDiameter = 200; //图表直径
$ChartFont = 2; //图表字体
$ChartFontHeight = imagefontheight($ChartFont);//图表字体的巨细
require('mysql.php3');
$sql=new mysql_class;
$sql->create('star');
$sql->query("select * from serch where answer='富士凡是昊 九段'");
$record1=$sql->rows;
$sql->query("select * from serch where answer='富士通曹薰铉 九段'");
$record2=$sql->rows;
$ChartData = array( $record1,$record2);//用于生成图表的数据,可经由过程数据库来获得来肯定
//$ChartLabel = array("常昊九段", "曹薰铉九段"); //数据对应的称号
//肯定图形的巨细
$ChartWidth = $ChartDiameter + 20;
$ChartHeight = $ChartDiameter + 20 +
(($ChartFontHeight + 2) * count($ChartData));
//肯定统计的总数
for($index = 0; $index < count($ChartData); $index++)
{
$ChartTotal += $ChartData[$index];
}
$ChartCenterX = $ChartDiameter/2 + 10;
$ChartCenterY = $ChartDiameter/2 + 10;
//生成空白图形
$image = imagecreate($ChartWidth, $ChartHeight);
//分派色彩
$colorBody = imagecolorallocate($image, 0xe4, 0xe6, 0xd1);
$colorBorder = imagecolorallocate($image, 0x00, 0x00, 0x00);
$colorText = imagecolorallocate($image, 0x00, 0x00, 0x00);
$colorSlice[] = imagecolorallocate($image, 0xFF, 0x00, 0x00);
$colorSlice[] = imagecolorallocate($image, 0x00, 0x00, 0xFF);
//填充背境
imagefill($image, 0, 0, $colorBody);
/*
** 画每个扇形
*/
$Degrees = 0;
for($index = 0; $index < count($ChartData); $index++)
{
$StartDegrees = round($Degrees);
$Degrees += (($ChartData[$index]/$ChartTotal)*360);
$EndDegrees = round($Degrees);
$CurrentColor = $colorSlice[$index%(count($colorSlice))];
//绘图F
imagearc($image,$ChartCenterX,$ChartCenterY,$ChartDiameter,
$ChartDiameter,$StartDegrees,$EndDegrees, $CurrentColor);
//画直线
list($ArcX, $ArcY) = circle_point($StartDegrees, $ChartDiameter);
imageline($image,$ChartCenterX,$ChartCenterY,floor($ChartCenterX + $ArcX),
floor($ChartCenterY + $ArcY),$CurrentColor);
//画直线
list($ArcX, $ArcY) = circle_point($EndDegrees, $ChartDiameter);
imageline($image,$ChartCenterX,$ChartCenterY,ceil($ChartCenterX + $ArcX),
ceil($ChartCenterY + $ArcY),$CurrentColor);
//填充扇形
$MidPoint = round((($EndDegrees - $StartDegrees)/2) + $StartDegrees);
list($ArcX, $ArcY) = circle_point($MidPoint, $ChartDiameter/2);
imagefilltoborder($image,floor($ChartCenterX + $ArcX),floor($ChartCenterY + $ArcY),
$CurrentColor,$CurrentColor);
}
//画边框
imagearc($image,
$ChartCenterX,
$ChartCenterY,
$ChartDiameter,
$ChartDiameter,
0,
180,
$colorBorder);
imagearc($image,
$ChartCenterX,
$ChartCenterY,
$ChartDiameter,
$ChartDiameter,
180,
360,
$colorBorder);
imagearc($image,
$ChartCenterX,
$ChartCenterY,
$ChartDiameter+7,
$ChartDiameter+7,
0,
180,
$colorBorder);
imagearc($image,
$ChartCenterX,
$ChartCenterY,
$ChartDiameter+7,
$ChartDiameter+7,
180,
360,
$colorBorder);
imagefilltoborder($image,
floor($ChartCenterX + ($ChartDiameter/2) + 2),
$ChartCenterY,
$colorBorder,
$colorBorder);
//绘图例
for($index = 0; $index < count($ChartData); $index++)
{
$CurrentColor = $colorSlice[$index%(count($colorSlice))];
$LineY = $ChartDiameter + 20 + ($index*($ChartFontHeight+2));
//draw color box
imagerectangle($image,
10,
$LineY,
10 + $ChartFontHeight,
$LineY+$ChartFontHeight,
$colorBorder);
imagefilltoborder($image,
12,
$LineY + 2,
$colorBorder,
$CurrentColor);
//画标签
imagestring($image,
$ChartFont,
20 + $ChartFontHeight,
$LineY,
"$ChartData[$index]",
$colorText);
}
//到此剧本 已生了一幅图象的,如今需求的是把它发到阅读器上,主要的一点是要将标头发给阅读器,让它晓得是一个GIF文件。否则的话你只能看到一堆奇异的乱码
header("Content-type: image/gif");
//输入生成的图片
imagegif($image);
?>
基础这个东西,有人问学php需要任何基础不? |
|