我的代码用于生成图像数组有点复杂,但总体思路是创建 8 个饼图,然后需要将其显示在表格的一列图表中。在我的 html 中获取图像我做错了什么。此函数与 html.xml 位于同一文件中。
构建图像
$FileHandle = fopen($FileName, 'r') or die("can't open file!!");
//Getting total for each question
$i = 0;
$start = 0;
$finish = 0;
while (($row = fgetcsv($FileHandle, 1024, ",")) !== FALSE) {
$total[] = $row[0] + $row[1] + $row[2] + $row[3] + $row[4];
$average[] = round(((1 * $row[0] + 2 * $row[1] + 3 * $row[2] + 4 * $row[3] + 5 * $row[4]) / $total[$i]), 2, PHP_ROUND_HALF_UP);
$start = 0;
$finish = 0;
$myImage[$i] = ImageCreate(200, 200);
$white = ImageColorAllocate($myImage[$i], 255, 255, 255);
$red = ImageColorAllocate($myImage[$i], 255, 0, 0);
$orange = ImageColorAllocate($myImage[$i], 191, 64, 0);
$olive = ImageColorAllocate($myImage[$i], 128, 128, 0);
$green = ImageColorAllocate($myImage[$i], 64, 191, 0);
$lt_green = ImageColorAllocate($myImage[$i], 0, 255, 0);
$finish = ($row[0] / $total[$i]) * 360;
//echo $start . ' ' . $finish . '<br>';
if ($finish != $start) {
ImageFilledArc($myImage[$i], 100, 100, 50, 50, $start, $finish, $red, IMG_ARC_PIE);
$start = $finish;
$finish += ($row[1] / $total[$i]) * 360;
}
else{
$start = $finish;
$finish += ($row[1] / $total[$i]) * 360;
}
if ($finish != $start) {
ImageFilledArc($myImage[$i], 100, 100, 50, 50, $start, $finish, $orange, IMG_ARC_PIE);
$start = $finish;
$finish += ($row[2] / $total[$i]) * 360;
}
else{
$start = $finish;
$finish += ($row[2] / $total[$i]) * 360;
}
if ($finish != $start) {
ImageFilledArc($myImage[$i], 100, 100, 50, 50, $start, $finish, $olive, IMG_ARC_PIE);
$start = $finish;
$finish += ($row[3] / $total[$i]) * 360;
}
else{
$start = $finish;
$finish += ($row[3] / $total[$i]) * 360;
}
if ($finish != $start) {
ImageFilledArc($myImage[$i], 100, 100, 50, 50, $start, $finish, $green, IMG_ARC_PIE);
$start = $finish;
$finish += ($row[4] / $total[$i]) * 360;
}
else{
$start = $finish;
$finish += ($row[4] / $total[$i]) * 360;
}
if ($finish != $start) {
ImageFilledArc($myImage[$i], 100, 100, 50, 50, $start, $finish, $lt_green, IMG_ARC_PIE);
}
$i++;
}
这是我在 html 块中尝试的内容
<td><?php echo $average[0] ?></td>
<td><?php imagepng($myImage[0]); ?></td>
<td><?php echo $total[0] ?></td>