那位大哥有画直方图与曲线图的源代码,100分相送!!!

52juanjuan 2004-04-04 06:15:09
在线等急需一画直方图与曲线图的源代码,最好能够写成函数,小生有礼了,如果能够提供gd的相关资料(手册中介绍的除外)也可以,谢谢各位
...全文
87 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
52juanjuan 2004-04-05
  • 打赏
  • 举报
回复
没有人给我回答???高手帮帮忙呀
52juanjuan 2004-04-05
  • 打赏
  • 举报
回复
为什么下面的也不行呀
<?//图类
Class ImageReport{
var $X;//图片大小X轴
var $Y;//图片大小Y轴
var $R;//背影色R值
var $G;//...G.
var $B;//...B.
var $TRANSPARENT;//是否透明1或0
var $IMAGE;//图片对像
//-------------------
var $ARRAYSPLIT;//指定用于分隔数值的符号
var $ITEMARRAY;//数值
var $REPORTTYPE;//图表类型,1为竖柱形2为横柱形3为折线形
var $BORDER;//距离
//-------------------
var $FONTSIZE;//字体大小
var $FONTCOLOR;//字体颜色
//--------参数设置函数
function setImage($SizeX,$SizeY,$R,$G,$B,$Transparent){
$this->X=$SizeX;
$this->Y=$SizeY;
$this->R=$R;
$this->G=$G;
$this->B=$B;
$this->TRANSPARENT=$Transparent;
}
function setItem($ArraySplit,$ItemArray,$ReportType,$Border){
$this->ARRAYSPLIT=$ArraySplit;
$this->ITEMARRAY=$ItemArray;
$this->REPORTTYPE=$ReportType;
$this->BORDER=$Border;
}
function setFont($FontSize){
$this->FONTSIZE=$FontSize;
}
//----------------主体
function PrintReport(){
//建立画布大小
$this->IMAGE=ImageCreate($this->X,$this->Y);
//设定画布背景色
$background=ImageColorAllocate($this->IMAGE,$this->R,$this->G,$this->B);
if($this->TRANSPARENT=="1"){
//背影透明
Imagecolortransparent($this->IMAGE,$background);
}else{
//如不要透明时可填充背景色
ImageFilledRectangle($this->IMAGE,0,0,$this->X,$this->Y,$background);
}
//参数字体文小及颜色
$this->FONTCOLOR=ImageColorAllocate($this->IMAGE,255-$this->R,255-$this->G,255-$this->B);
Switch ($this->REPORTTYPE){
case "0":
break;
case "1":
$this->imageColumnS(); //竖矩状图
break;
case "2":
$this->imageColumnH(); //横矩状图
break;
case "3":
$this->imageLine(); //折线图
break;
case "4":
$this->imageCircle(); //饼图
break;
}
$this->printXY();
$this->printAll();
}
//-----------打印XY坐标轴
function printXY(){
//画XY坐标轴*/
$color=ImageColorAllocate($this->IMAGE,255-$this->R,255-$this->G,255-$this->B);
$xx=$this->X/10;
$yy=$this->Y-$this->Y/10;
ImageLine($this->IMAGE,$this->BORDER,$this->BORDER,$this->BORDER,$this->Y-$this->BORDER,$color);//X轴
ImageLine($this->IMAGE,$this->BORDER,$this->Y-$this->BORDER,$this->X-$this->BORDER,$this->Y-$this->BORDER,$color);//y轴
//Y轴上刻度
$rulerY=$this->Y-$this->BORDER;
while($rulerY>$this->BORDER*2){
$rulerY=$rulerY-$this->BORDER;
ImageLine($this->IMAGE,$this->BORDER,$rulerY,$this->BORDER-2,$rulerY,$color);
}
//X轴上刻度
$rulerX=$rulerX+$this->BORDER;
while($rulerX<($this->X-$this->BORDER*2)){
$rulerX=$rulerX+$this->BORDER;
//ImageLine($this->IMAGE,$this->BORDER,10,$this->BORDER+10,10,$color);
ImageLine($this->IMAGE,$rulerX,$this->Y-$this->BORDER,$rulerX,$this->Y-$this->BORDER+2,$color);
}
}

//--------------竖柱形图
function imageColumnS(){
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);
$num=Count($item_array);
$item_max=0;
for ($i=0;$i<$num;$i++){
$item_max=Max($item_max,$item_array[$i]);
}
$xx=$this->BORDER*2;
//画柱形图
for ($i=0;$i<$num;$i++){
srand((double)microtime()*1000000);
if($this->R!=255 && $this->G!=255 && $this->B!=255){
$R=Rand($this->R,200);
$G=Rand($this->G,200);
$B=Rand($this->B,200);
}else{
$R=Rand(50,200);
$G=Rand(50,200);
$B=Rand(50,200);
}
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
//柱形高度
$height=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($item_array[$i]/$item_max);
ImageFilledRectangle($this->IMAGE,$xx,$height,$xx+$this->BORDER,$this->Y-$this->BORDER,$color);
ImageString($this->IMAGE,$this->FONTSIZE,$xx,$height-$this->BORDER,$item_array[$i],$this->FONTCOLOR);
//用于间隔
$xx=$xx+$this->BORDER*2;
}
}
//-----------横柱形图
function imageColumnH(){
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);
$num=Count($item_array);
$item_max=0;
for ($i=0;$i<$num;$i++){
$item_max=Max($item_max,$item_array[$i]);
}
$yy=$this->Y-$this->BORDER*2;
//画柱形图
for ($i=0;$i<$num;$i++){
srand((double)microtime()*1000000);
if($this->R!=255 && $this->G!=255 && $this->B!=255){
$R=Rand($this->R,200);
$G=Rand($this->G,200);
$B=Rand($this->B,200);
}else{
$R=Rand(50,200);
$G=Rand(50,200);
$B=Rand(50,200);
}
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
//柱形长度
$leight=($this->X-$this->BORDER*2)*($item_array[$i]/$item_max);
ImageFilledRectangle($this->IMAGE,$this->BORDER,$yy-$this->BORDER,$leight,$yy,$color);
ImageString($this->IMAGE,$this->FONTSIZE,$leight+2,$yy-$this->BORDER,$item_array[$i],$this->FONTCOLOR);
//用于间隔
$yy=$yy-$this->BORDER*2;
}
}


//--------------折线图
function imageLine(){
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);
$num=Count($item_array);
$item_max=0;
for ($i=0;$i<$num;$i++){
$item_max=Max($item_max,$item_array[$i]);
}
//$xx=$this->BORDER;
//画柱形图
for ($i=0;$i<$num;$i++){
srand((double)microtime()*1000000);
if($this->R!=255 && $this->G!=255 && $this->B!=255){
$R=Rand($this->R,200);
$G=Rand($this->G,200);
$B=Rand($this->B,200);
}else{
$R=Rand(50,200);
$G=Rand(50,200);
$B=Rand(50,200);
}
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
//柱形高度
$height_now=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($item_array[$i]/$item_max);
if($i!="0"){
ImageLine($this->IMAGE,$xx,$height_next,$xx+$this->BORDER,$height_now,$color);
}
ImageString($this->IMAGE,$this->FONTSIZE,$xx+$this->BORDER,$height_now-$this->BORDER/2,$item_array[$i],$this->FONTCOLOR);
$height_next=$height_now;
//用于间隔
$xx=$xx+$this->BORDER;
}
}
//--------------饼状图
function imageCircle(){
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);
$num=Count($item_array);
$item_max=0;
for ($i=0;$i<$num;$i++){
$item_max=Max($item_max,$item_array[$i]);
$total += $item_array[$i];
}
$yy=$this->Y-$this->BORDER*2;

//画饼状图的阴影部分
$e=0;
for ($i=0;$i<$num;$i++){
srand((double)microtime()*1000000);
if($this->R!=255 && $this->G!=255 && $this->B!=255){
$R=Rand($this->R,200);
$G=Rand($this->G,200);
$B=Rand($this->B,200);
}else{
$R=Rand(50,200);
$G=Rand(50,200);
$B=Rand(50,200);
}
$s=$e;
$leight=$item_array[$i]/$total*360;
$e=$s+$leight;
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
$colorarray[$i]=$color;
//画圆
for ($j = 90; $j > 70; $j--) imagefilledarc($this->IMAGE, 110, $j, 200, 100, $s, $e, $color, IMG_ARC_PIE);
//imagefilledarc($this->IMAGE, 110, 70, 200, 100, $s, $e, $color, IMG_ARC_PIE);
//ImageFilledRectangle($this->IMAGE,$this->BORDER,$yy-$this->BORDER,$leight,$yy,$color);
//ImageString($this->IMAGE,$this->FONTSIZE,$leight+2,$yy-$this->BORDER,$item_array[$i],$this->FONTCOLOR);
//用于间隔
$yy=$yy-$this->BORDER*2;
}

//画饼状图的表面部分
$e=0;
for ($i=0;$i<$num;$i++){
srand((double)microtime()*1000000);
if($this->R!=255 && $this->G!=255 && $this->B!=255){
$R=Rand($this->R,200);
$G=Rand($this->G,200);
$B=Rand($this->B,200);
}else{
$R=Rand(50,200);
$G=Rand(50,200);
$B=Rand(50,200);
}
$s=$e;
$leight=$item_array[$i]/$total*360;
$e=$s+$leight;
//$color=$colorarray[$i];
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
//画圆
//for ($j = 90; $j > 70; $j--) imagefilledarc($this->IMAGE, 110, $j, 200, 100, $s, $e, $color, IMG_ARC_PIE);
imagefilledarc($this->IMAGE, 110, 70, 200, 100, $s, $e, $color, IMG_ARC_PIE);
}
}
//--------------完成打印图形
function printAll(){
ImagePNG($this->IMAGE);
ImageDestroy($this->IMAGE);
}
lonelydreamsym 2004-04-05
  • 打赏
  • 举报
回复
to: zhuomaocn(烦啊)
我用你的代码怎么什么也没划出来呢,也没任何错误提示。
xumail 2004-04-05
  • 打赏
  • 举报
回复
up
zhuomaocn 2004-04-05
  • 打赏
  • 举报
回复
<html>

<OBJECT id=StructuredGraphicsControl1 style="LEFT: 0px; WIDTH: 392px; TOP: 0px; HEIGHT: 240px"
height=240 width=392 classid="clsid:369303C2-D7AC-11D0-89D5-00A0C90833E6">

</OBJECT>
<P> </P>
<SCRIPT LANGUAGE=vbscript>

StructuredGraphicsControl1.DrawingSurface.ArcDegrees 0,0,0,30,50,60
StructuredGraphicsControl1.DrawingSurface.ArcRadians 30,0,0,30,50,60
StructuredGraphicsControl1.DrawingSurface.Line 10,10,100,100

</SCRIPT>
</html>
zhuomaocn 2004-04-05
  • 打赏
  • 举报
回复
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>emu's paint without vlm</title>
</head>
<body>
<button onclick="testDrawCurve()">画曲线</button>
<button onclick="testDrawArc()">画弧线</button>
<button onclick="testDrawCircle()">画圆</button>
<button onclick="testDrawLine()">画线</button>
<button onclick="testDrawRectangle()">画矩形</button>
<button onclick="testDrawPie()">画饼图</button>
<div id=div1></div>
<SCRIPT LANGUAGE="JavaScript">
<!--
function testDrawCurve()
{
div1.innerHTML = drawCurve();
}
function testDrawArc()
{
div1.innerHTML =drawArc(150,150,100,0,270,"viloet")
}
function testDrawCircle()
{
div1.innerHTML = drawCircle(200,200,150,"blue");
}
function drawCircle(x0,y0,radius,color)
{
return drawArc(x0,y0,radius,0,360,color)
}
function testDrawLine()
{
div1.innerHTML = drawLine(100,200,500,200,"yellow")+drawLine(300,100,300,400,"black")+drawLine(600,400,100,100,"violet")
}
function testDrawRectangle()
{
div1.innerHTML = drawRectangle(200,100,600,200,"blue")+drawRectangle(100,200,400,500,"red")
}
function testDrawPie()
{
div1.innerHTML = drawPie(300,200,120,0,45,"red");
}

function drawLine(x0,y0,x1,y1,color)
{
var rs = "";
if (y0 == y1) //画横线
{
rs = "<table style='top:"+y0+";left:"+x0+";position:absolute'><td bgcolor="+color+" height=3 width="+Math.abs(x1-x0)+"></td></table>";
}
else if (x0 == x1) //画竖线
{
rs = "<table style='top:"+y0+";left:"+x0+";position:absolute'><td bgcolor="+color+" width=1 height="+Math.abs(y1-y0)+"></td></table>";
}
else
{
var lx = x1-x0
var ly = y1-y0
var l = Math.sqrt(lx*lx+ly*ly)
rs = new Array();
for (var I=0;I<l;I+=1)
{
var p = I/l;
var px = x0 + lx*p;
var py = y0 + ly*p;
rs[rs.length] = "<table style='top:"+py+";left:"+px+";position:absolute'><td bgcolor="+color+" height=3></td></table>";
}
rs = rs.join("");
}
return rs
}
function drawRectangle(x0,y0,x1,y1,color)
{
if (x0 == x1 || y0 == y1) return;
if (x0>x1) {var t=x0;x0=x1;x1=t}
if (y0>y1) {var t=y0;y0=y1;y1=t}
return "<table style='top:"+y0+";left:"+x0+";position:absolute'><td bgcolor="+color+" width="+(x1-x0)+" height="+(y1-y0)+"></td></table>";
}
function drawPie(x0,y0,radius,startAngle,endAngle,color)
{
var rs = drawArc(x0,y0,radius,startAngle,endAngle,color)
startAngle = startAngle/360*Math.PI*2;
endAngle = endAngle/360*Math.PI*2;
var startx=Math.sin(startAngle)*radius+x0;
var endx=Math.sin(endAngle)*radius+x0;
var starty=Math.cos(startAngle)*radius+y0;
var endy=Math.cos(endAngle)*radius+y0;
rs += drawLine(x0,y0,startx,starty,color)
rs += drawLine(x0,y0,endx,endy,color)
return rs;
}
function drawArc(x0,y0,radius,startAngle,endAngle,color)
{
rs = new Array();
tmpar = new Array();
startAngle = startAngle/360*Math.PI*2;
endAngle = endAngle/360*Math.PI*2;
for (var I=startAngle;I<endAngle;I+=(1/radius))
{
var dx = Math.sin(I)*radius+x0;
var dy = Math.cos(I)*radius+y0;
rs[rs.length] = "<table style='top:"+dy+";left:"+dx+";position:absolute'><td bgcolor="+color+" height=3></td></table>";
}
return (rs.join(""));
}
function drawCurve()
{
var rs = new Array();
for (var I=0;I<2*Math.PI;I+=.02)
{
var x = 300-Math.sin(I)*100
var y = 300-Math.cos(I)*100
rs[rs.length] = "<table style='top:"+x+";left:"+(I*100+90)+";position:absolute'><td bgcolor=blue height=3></td></table>";
rs[rs.length] = "<table style='top:"+y+";left:"+(I*100+90)+";position:absolute'><td bgcolor=violet height=3></td></table>";
}
return rs.join("");
}
//-->
</SCRIPT>
</body>
</html>
52juanjuan 2004-04-05
  • 打赏
  • 举报
回复
谢了
52juanjuan 2004-04-05
  • 打赏
  • 举报
回复
up
多菜鸟 2004-04-04
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2758/2758503.xml?temp=.2989618
52juanjuan 2004-04-04
  • 打赏
  • 举报
回复
没有人有呀

21,886

社区成员

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

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