我想要做的是从csv文件加载一些值,并使用它们作为x,y值来绘制一些矩形。基于csv数据的php绘图
我正在加载文件,但不是显示图像,而是输出原始图像数据。我知道,在HTML代码中,我可以使用
<img scr="foo.php"></script>
正确显示图像,但我不知道怎么用这个来绘制基于关闭数据的每一行的csv文件的多个矩形。请帮忙。
CSV代码
20,40,60,80
50,100,150,175
索引PHP代码
<html>
<body>
<?php
include("parse.php");
?>
</body>
</html>
解析PHP代码
<?php
include("draw.php");
$file = fopen("data.csv", "r");
while (!feof($file)) {
$line = fgetcsv($file);
drawGraph($line[0], $line[1], $line[2], $line[3]);
}
fclose($file);
?>
拉伸PHP代码
<?php
function drawGraph($xPos, $yPos, $xxPos, $yyPos) {
//create a 200 x 200 canvas image
$canvas = imagecreatetruecolor(200, 200);
//set canvas background to white
$white = imagecolorallocate($canvas, 255, 255, 255);
imagefill($canvas, 0, 0, $white);
//create colors
$pink = imagecolorallocate($canvas, 255, 105, 180);
//draw rectangles
imagerectangle($canvas, $xPos, $yPos, $xxPos, $yyPos, $pink);
//ERROR - following line displays raw data of image not the actural image
imagepng($canvas);
imagedestroy($canvas);
}
?>
我实际上并没有完全理解你,但也许这有助于:记住在推送原始数据之前做header('Content-Type:image/png')。 – 2012-08-12 00:56:41
你可以发布产生的HTML吗? – SomeKittens 2012-08-12 00:58:33
这是一些无头‰PNGIHDRÈÈ“HTML输出的:9E =IDATxœíÜÁ\t A0A;¤»t',Ò‰ëSÈÃA^ FAE /吨ýnclpμÇê¸'a '\t一个' \t一个 '\t一个' \t一个'\t一个' \t一个 '\t一个' \t一个 '\t一个' \t一个 '\t一个' \t一个 '\t一个' \t一个 '\t一个' \t一个 '\t一个' \t一个'‰COE÷qÑÿû¼-]Í \t sam
user1334130
2012-08-12 01:26:48