简体   繁体   English

使用php创建饼图

[英]create a pie chart using php

I saw a tutorial online where they claim that the code below makes a pie chart.我在网上看到一个教程,他们声称下面的代码制作了饼图。 Yet when I run this exact code i have the error Fatal error: Call to undefined function imagecolorsallocate() in / **/** / * /piechart.php on line 7 (I've used asterix to cover my folders names).然而,当我运行这个确切的代码时,我在第 7 行出现了错误 Fatal error: Call to undefined function imagecolorsallocate() in / **/** / * /piechart.php (我使用 asterix 来覆盖我的文件夹名称)。 Any suggestions?有什么建议? Or is there any other way to create one preferably without using third party material.或者有没有其他方法可以最好地创建一个而不使用第三方材料。

<?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);
?>

Thanks谢谢

It should of been imagecolourallocate not imagecoloursallocate.它应该是 imagecolourallocate 而不是 imagecoloursallocate。 This would not of been spotted if it were not for Class如果不是因为 Class 就不会被发现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM