>  기사  >  백엔드 개발  >  PHP를 사용하여 선형 차트 기능을 만드는 방법

PHP를 사용하여 선형 차트 기능을 만드는 방법

高洛峰
高洛峰원래의
2016-12-02 11:20:531033검색

모두가 PHP(현재 주류 개발 언어)에 대한 애착을 갖고 있다는 사실이 기쁩니다!
다음은 꺾은선형 차트 작성을 위한 PHP(현재 주류 개발 언어)의 기능을 소개합니다:

/*
함수 설명
$data: y축 데이터( 배열)
$graphdata: y축 데이터 - 백분율(배열)
$label: x축 데이터(배열)
$height: 이미지 높이
$width: 이미지 너비
$ 글꼴: 글꼴 크기
$dot: 점 크기 결정
$bg: 배경색
$line: 선 색상
$text: 텍스트 색상
$dotcolor: 점 색상
$file: 출력 이미지 파일 이름
*/

function qximage($data,
$graphdata,
$label,
$height,
$width,
$font,
$dot,
$bg,
$line,
$text,
$dotcolor,
$file)
{
$jc =$height/100;$fontwidth= 이미지폰트폭($font)
$fontheight=imagefontheight($font)

$image= imagecreate($width,$height+20);
$bg= imagecolorallocate ($image ,$bg[0],$bg[1],$bg[2])
$line=imagecolorallocate($image ,$line[0],$line[ 1],$line[2 ]);
$text=imagecolorallocate($image ,$text[0],$text[1],$text[2])
$dotcolor=imagecolorallocate($image ,$dotcolor[0], $dotcolor[1],$$dotcolor[2])
imageline($image,0,0,0,$height,$line)
imageline($image, 0,$height,$width ,$height,$line)
for ($i=1;$i<11;$i++)
{
imagedashedline($image,0,$height - $jc*$i*10 ,$width ,$height -$jc*$i*10 ,$line )
imagestring($image,$font,0,$height-$jc*$i*10, $i*10,$text );
}
for ($i=0;$i {
#echo $tmp."
";
$x1=(($width -50)/개수($ 데이터))*($i)+40;
#echo $x1 ."
"
$y1=$height-$graphdata[$i]*$jc ;
$x2= $x1;
$y2=$y1+$graphdata[$i]*$jc
#echo $y1."
imagestring($image, $font,$x1,$ y1-2*$fontheight,$graphdata[$i]."%(".$data[$i].")",$text)
imagearc($image,$ x1 ,$y1,$dot ,$dot,0,360,$dotcolor);
imagefilltoborder($image,$x1,$y1,$dotcolor,$dotcolor)
imagestring($image,$font,$ x1,$y2,$label [$i],$text)
if ($i>0)
{
imageline($image,$tmpx1,$tmpy1,$x1,$y1, $line)
}
$tmpx1=$x1;$tmpy1=$y1;
}
imagegif($image,$file)
}
? 🎜>

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.