رسم نمودار با php

oldooz

Well-Known Member
سلام دوست عزیز
این کد رو همین الان نوشتم...
شاید به دردت بخوره
نمودار تابع f(x)=x^2 هستش البته ایراد و اشکال زیاد داره ولی خب همینطوری سرپایی نوشتمش

کد:
header("Content-type: image/png");
$image=imagecreate(400,400);
$black=imagecolorallocate($image,0,0,0);
$white=imagecolorallocate($image,255,255,255);
imageline($image,200,0,200,400,$white);
imageline($image,0,200,400,200,$white);
$x=-20;
$x2;
$y;
$i=1;
while($i<150) {
$x2=$x;
imagesetpixel($image,($x)+200,200-(pow($x,2)),$white);
$i++;
$x++;
imageline($image,$x+200,200-(pow($x,2)),$x2+200,200-(pow($x2,2)),$white);
}
imagegif($image);
 

foranyone

Well-Known Member
دستت درد نکنه ولی ایشون که نمیخوان نمودار ریاضی رسم کنن ! میخوان نمودار آماری رسم کنن مثلا یه نمودار از تعداد دانشجویان تنبل و زرنگ .
 

oldooz

Well-Known Member
بله میدونم ولی خب اگه بخواید نموداری به این شکل(خطی) رسم کنید مثلا در مدت زمانی(محور xها) فعالیت دانشجویان(محور yها) چطور بوده؟!
نحوه نقطه یابی و وصل کردن نقطه ها به نظرم یکیه
حالا بازم اگه اشتباه میکنم راهنماایم کنید...
 

oldooz

Well-Known Member
سلام دوستان
اون کدرو یکم ویرایشش کردم
تقریبا واسه اکثر توابع جواب میده
کد:
header("Content-type: image/png");
$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,$counter+40,$blue);
}else {
imagefilledrectangle($image,0,$counter,400,$counter+40,$bluekam);
}
$counter=$counter+40;
$counter2++;
}
$counter=0;
while($counter<400) {
imagedashedline($image,$counter,0,$counter,400,$white);
$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,$font,$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,$font,$counter2);
}
$counter+=40;
$counter2++;
}
imagegif($image);
 

جدیدترین ارسال ها

بالا