PDA

View Full Version : سوال: رسم نمودار در php



monaizadi
دوشنبه 27 خرداد 1387, 22:18 عصر
سلام
می خواستم بدونم چطوری در php می تونم نمودار f(x)=x^2 - x را رسم کنم.

yaqubian
سه شنبه 28 خرداد 1387, 00:36 صبح
دوست عزیز یه سیستم open source هست به اسم Graph Plotter
که لینک دانلودش رو واست می ذارم. امیدوارم بدردت بخوره اگه چیزه دیگه ای پیدا کردم خبرت می کنم
موفق باشی
http://www.lukewallin.co.uk/index.php?go=graph

aoldooz
پنج شنبه 05 شهریور 1388, 19:09 عصر
نمودار های آماده زیادی هست ولی...
خب پس کار برنامه نویس چیه؟
اینی که من نوشتم برای خیلی از ضابطه ها جواب میده ولی بعضی هاشونو مشکل داره که الان وقت ندارم اصلاحش کنم.
نمودار y=x^2


<?php
header("Content-type: image/gif");
$image=imagecreate(400,400);
$black=imagecolorallocate($image,0,0,0);
$white=imagecolorallocate($image,255,255,255);
$yellow=imagecolorallocate($image,255,255,128);
$bluekam=imagecolorallocate($image,90,90,90);
$blue=imagecolorallocate($image,63,63,63);
$red=imagecolorallocate($image,255,0,0);
imagefill($image,200,200,$bluekam);
$counter2=0;
$counter=0;
while($counter<400) {
if ($counter2 % 2 == 0){
imagefilledrectangle($image,0,$counter,400,$counte r+40,$blue);
}else {
imagefilledrectangle($image,0,$counter,400,$counte r+40,$bluekam);
}
$counter=$counter+40;
$counter2++;
}
$counter=0;
while($counter<400) {
imagedashedline($image,$counter,0,$counter,400,$wh ite);
$counter=$counter+40;
$counter2++;
}
$counter=0;
while($counter<400) {
if($counter==200){
imageline($image,0,$counter,400,$counter,$white);
}else{
imageline($image,0,$counter,400,$counter,$white);
}
$counter=$counter+40;
}

//noghteyabi va rasm
$x=-200;
$x2;
$y;
$i=1;
while($i<450) {
$x2=$x;
$x++;
$zabeteh=pow($x,2);
imagesetpixel($image,($x)+200,200-($zabeteh),$white);
$i++;
$zabeteh2=pow($x2,2);
imageline($image,$x+200,200-($zabeteh),$x2+200,200-($zabeteh2),$yellow);
}


imageline($image,200,0,200,400,$white);
imageline($image,0,200,400,200,$white);
$counter=400;
$counter2=-5;
$font="C:\WINDOWS\Fonts\symbol.ttf";
while($counter>=0) {
imagettftext($image,12,20,205,$counter,$white,$fon t,$counter2);
$counter-=40;
$counter2++;
}
$counter=0;
$counter2=-5;
$font="C:\WINDOWS\Fonts\symbol.ttf";
while($counter<400) {
if($counter != 200) {
imagettftext($image,12,20,$counter+5,198,$white,$f ont,$counter2);
}
$counter+=40;
$counter2++;
}
imagegif($image);
?>


فایل ضمیمه هم عکس حاصل از اجرای این برنامه هستش