在PHP如何绘制统计图,解答的100分奉上

tfxg 2003-05-20 11:05:37
在PHP如何绘制统计图,统计数据通过查询语句从MYSQL数据库中取出。
...全文
99 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2003-05-27
  • 打赏
  • 举报
回复
http://www.aditus.nu/jpgraph/
vitalgg 2003-05-20
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/1794/1794070.xml?temp=.1346552
xizi2002 2003-05-20
  • 打赏
  • 举报
回复
作参考吧
<html>
<head>
<title>柱状图</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF">
<?
/*
Written by Caocao.
http://caocao.oso.com.cn
caocao@eastday.com
*/
class bar
{
var $bar_width=15;//柱宽
var $bar_height=400;//最大柱高
var $bar_color_light="CCCCCC";//柱色
var $bar_color_dark="000000";//阴影色
var $shadow=3;//阴影深度
var $space=5;//柱间距
var $data;//数据
var $result;//结果
var $style=1;//柱图样式
var $ispercent=1;//是否用百分比

function set_width_height($bar_width_input,$bar_height_input)//设置柱宽柱高
{
$this->bar_width=$bar_width_input;
$this->bar_height=$bar_height_input;
}

function set_bar_color($bar_color_light_input,$bar_color_dark_input)//设置柱色阴影色
{
$this->bar_color_light=$bar_color_light_input;
$this->bar_color_dark=$bar_color_dark_input;
}

function set_style($style_input)//设置柱图样式
{
$this->style=$style_input;
}

function set_shadow($shadow_input)//设置阴影深度
{
$this->shadow=$shadow_input;
}

function set_space($space_input)//设置柱间距
{
$this->space=$space_input;
}

function set_ispercent($ispercent_input)//设置是否用百分比
{
$this->ispercent=$ispercent_input;
}

function set_data($data_input)//设置数据
{
for ($i=0;$i<count($data_input);$i++)
$this->data[$i]=$data_input[$i];
}

function preset_data()//数据处理
{
if ($this->ispercent)
{
$total_tmp=0;
for ($i=0;$i<count($this->data);$i++)
$total_tmp+=$this->data[$i];
for ($i=0;$i<count($this->data);$i++)
$this->result[$i]=number_format(100*$this->data[$i]/$total_tmp,1);
return (0);
}
else
{
$tmp[0]=$this->data[0];
$tmp[1]=$this->data[0];
for ($i=0;$i<count($this->data);$i++)
{
if ($tmp[0]>$this->data[$i])
$tmp[0]=$this->data[$i];
if ($tmp[1]<$this->data[$i])
$tmp[1]=$this->data[$i];
}
return ($tmp);
}
}

function style_1()
{
$tmp=$this->preset_data();
echo "<table border=0 cellspacing=0 cellpadding=".$this->space.">n";
if (count($tmp)==1)
{
for ($i=0;$i<count($this->result);$i++)
{
echo "<tr><td>".$this->result[$i]."%</td><td><table height=".$this->bar_width." width=".ceil($this->result[$i]*$this->bar_height/100)." border=0 cellspacing=0 cellpadding=0 bgcolor=".$this->bar_color_light."><tr><td></td></tr></table></td></tr>n";
}
}
else
{
for ($i=0;$i<count($this->data);$i++)
{
echo "<tr><td>".$this->data[$i]."</td><td><table height=".$this->bar_width." width=".ceil(100*($this->data[$i]-$tmp[0])/($tmp[1]-$tmp[0])+1)." border=0 cellspacing=0 cellpadding=0 bgcolor=".$this->bar_color_light."><tr><td></td></tr></table></td></tr>n";
}
}
echo "</table>n";
}

function display()//显示柱图
{
switch ($this->style)
{
case 1:$this->style_1();break;

}
}
}

$newdata=array(30,60,55,48,30,70,28,0);

$result=new bar;
$result->set_data($newdata);
$result->set_width_height(20,800);
$result->set_space(3);
$result->set_shadow(3);

$result->set_ispercent(0);
for ($i=1;$i<5;$i++)
{
$result->set_style($i);
$result->display();
}
$result->set_ispercent(1);
for ($i=1;$i<5;$i++)
{
$result->set_style($i);
$result->display();
}
?>
</body>
</html>
myaniu 2003-05-20
  • 打赏
  • 举报
回复
echo '<img src="../images/bar.gif" height="12" width="';
echo intval(100*$len/$maxlen).'%">';
//$maxlen为最长的一个柱
//$len为一般的柱
//bar.gif为一个条形图
//也可以改变height

21,881

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧