使用php创建一个饼图

时间:2014-04-14 08:53:24

标签: php html graph pie-chart

我在网上看到一个教程,他们声称下面的代码制作了一个饼图。然而,当我运行这个确切的代码我有错误致命错误:调用未定义的函数imagecolorsallocate()在/**/**/*/piechart.php在线7(我使用asterix来覆盖我的文件夹名称)。有什么建议?或者是否有其他方法可以在不使用第三方材料的情况下创建一个。

<?php

//create image
$image = imagecreatetruecolor(100,100);

//allocate some colour
$white = imagecolorsallocate($image, 0xFF , 0xFF, 0xFF);
$gray = imagecolorsallocate($image, 0xC0 , 0xC0, 0xC0);
$darkgray = imagecolorsallocate($image, 0x90 , 0x90, 0x90);
$navy = imagecolorsallocate($image, 0x00 , 0x00, 0x80);
$darknavy = imagecolorsallocate($image, 0x00 , 0x00, 0x05);
$red = imagecolorsallocate($image, 0xFF , 0x00, 0x00);
$darkred = imagecolorsallocate($image, 0x90, 0x00, 0x00);

//make the 3d effect
for($i = 60; $i >50; $i--){
imagefilledarc($image, 50, $i, 100, 50, 0, 45, $darknavy, IMG_ARC_PIE);
imagefilledarc($image, 50, $i, 100, 50, 45, 75, $darkgray, IMG_ARC_PIE);
imagefilledarc($image, 50, $i, 100, 50, 75, 360, $darkred, IMG_ARC_PIE);
}
imagefilledarc($image ,50 ,50 , 100, 50, 0, 45, $navy, IMG_ARC_PIE);
imagefilledarc($image ,50 ,50 , 100, 50, 45, 75, $gray, IMG_ARC_PIE);
imagefilledarc($image ,50 ,50 , 100, 50, 75, 360, $red, IMG_ARC_PIE);

//flush image
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>

由于

1 个答案:

答案 0 :(得分:0)

它应该是imagecolourallocate而不是imagecoloursallocate。如果不是Class

,就不会发现这种情况