【问题标题】:create a pie chart using php使用 php 创建饼图
【发布时间】:2014-04-14 08:53:24
【问题描述】:

我在网上看到一个教程,他们声称下面的代码制作了一个饼图。然而,当我运行这个确切的代码时,我有错误 Fatal error: Call to undefined function imagecolorsallocate() in /**/**/*/piechart.php on line 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);
?>

谢谢

【问题讨论】:

  • imagecolorsallocate !== imagecolorallocate
  • 您是否在 PHP 配置中启用了 GD 扩展?
  • @Class 感谢愚蠢的错误无法发现!您刚刚为我节省了数小时的研究时间

标签: php html graph pie-chart


【解决方案1】:

应该是 imagecolourallocate 而不是 imagecoloursallocate。如果不是 Class 就不会被发现

【讨论】:

  • 你的意思是imagecolorallocate你刚才说imagecolourallocate这是不正确的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多