原创内容....实现曲线图,饼图,柱形图.
转贴请注明出处,
http://blog.youkuaiyun.com/liq330
效果图:


原代码如下:
<?
php

class
ImageReport
{
var
$Image
;
//
图片对像
var
$ImageName
;
//
报表名称
var
$ImageType
;
//
报表类型
var
$ImageWidth
;
//
图片宽
var
$ImageHeight
;
//
图片高

var
$BgImage
;
//
背景图片
var
$BgR
;
//
背景颜色R值
var
$BgG
;
//
背景颜色G值
var
$BgB
;
//
背景颜色B值
var
$FontSize
;
//
字体大小
var
$FontColor
;
//
字体颜色
var
$ItemArray
;
//
数据数组
var
$ItemInterval
;
//
两项间的间隔
var
$XName
;
//
x轴的名称
var
$YName
;
//
y轴的名称
var
$isScale
;
//
是否显示刻度值
var
$margin
;
//
边距

//字体
var
$font
=
'
arial.ttf
'
;
function
ImageReport()
{
return
;
}

//
设置图片基本信息
function
setImage(
$ImageName
,
$ImageType
,
$ImageWidth
=
500
,
$ImageHeight
=
400
)
{
$this
->
ImageName
=
$ImageName
;
$this
->
ImageType
=
$ImageType
;
$this
->
ImageWidth
=
$ImageWidth
;
$this
->
ImageHeight
=
$ImageHeight
;
}
//
设置坐标
function
setItem(
$ItemArray
,
$ItemInterval
=
"
20
"
,
$XName
=
""
,
$YName
=
""
,
$isScale
=
true
)
{
$this
->
ItemArray
=
$ItemArray
;
$this
->
ItemInterval
=
$ItemInterval
;
$this
->
XName
=
$XName
;
$this
->
YName
=
$YName
;
$this
->
isScale
=
$isScale
;
}
//
设置图片背景
function
setBg(
$BgR
=
"
235
"
,
$BgG
=
"
255
"
,
$BgB
=
"
255
"
,
$BgImage
=
""
)
{
$this
->
BgR
=
$BgR
;
$this
->
BgG
=
$BgG
;
$this
->
BgB
=
$BgG
;
$this
->
BgImage
=
$BgImage
;
}
//
设置字体
function
setFont(
$FontSize
)
{
$this
->
FontSize
=
$FontSize
;
$this
->
margin
=
$FontSize
*
2
+
5
;
//
$this->FontColor =$FontColor;
}

//
画主体
function
drawReport()
{
//
建立画布
$this
->
Image
=
imagecreatetruecolor(
$this
->
ImageWidth
,
$this
->
ImageHeight);
//
填充背景色
$background
=
ImageColorAllocate(
$this
->
Image
,
$this
->
BgR
,
$this
->
BgG
,
$this
->
BgB);
//
画背景颜色
ImageFilledRectangle(
$this
->
Image
,
0
,
0
,
$this
->
ImageWidth
,
$this
->
ImageHeight
,
$background
);

//
画背景图片
if
(
!
empty
(
$this
->
BgImage))
{
$this
->
drawLogo();
}
//
跟距参数,画不同的图片
switch
(
$this
->
ImageType)
{
case
"
1
"
:
$this
->
drawColumn();
break
;
case
"
2
"
:
$this
->
drawCurve();
break
;
case
"
3
"
:
$this
->
drawCircle();
break
;
default
:
break
;
}

}
//
画柱状图
function
drawColumn()
{
//
调用画标题
$this
->
drawTitle();
//
调用画坐标
$this
->
drawXY();

//
获取数组的量
$num
=
count
(
$this
->
ItemArray);
//
获取数组中的最大值
//最大值
$max
=
$this
->
getArrayMax(
$this
->
ItemArray);

for
(
$i
=
0
;
$i
<
count
(
$this
->
ItemArray);
$i
++
)
{
//
随机颜色
srand
((
double
)
microtime
()
*
1000000
);
$R
=