Jump to content
crs12decoder

grafic php

Recommended Posts

http://crs12decoder.comoj.com/interfata.php

Pentru nevoi personale am facut un script php de generat grafice dupa puncte de coordonate.

Preview: http://crs12decoder.comoj.com/grafic.php

Poate mai are cineva nevoie de asa ceva asa ca-l postez aici:


<?php
$puncte = array(
1 => '0,0',
2 => '3,2',
3 => '5,7',
4 => '8,4'
);

$linii = 10;
$coloane = 20;

header ("Content-type: image/jpeg");
$height = 250;
$width = 600;
$img = imagecreate ($width,$height);
$fond = imagecolorallocate ($img,211,211,211);
$col = imagecolorallocate ($img,0,0,0);
$linecol = imagecolorallocate ($img,82,10,26);
$textcol = imagecolorallocate ($img,0,34,102);

imageline ($img,0,$width,0,0,$col);
imageline ($img,$width,0,0,0,$col);
imageline ($img,0,$height-1,$width,$height-1,$col);
imageline ($img,$width-1,0,$width-1,$height,$col);

//forsyn
$ay=0;
for($i=0; $i<=$linii; $i++){
$ay=$ay+$height/$linii;
imageline ($img,0,$ay,$width,$ay,$col);
}
//forsyn

//forsxn
$ay=0;
for($i=0; $i<=$coloane; $i++){
$ay=$ay+$width/$coloane;
imageline ($img,$ay,0,$ay,$height,$col);
}
//forsxn

for($i=1; $i<=count($puncte); $i++){
$exp = explode(',', $puncte[$i]);
$x[$i] = $exp[0];
$y[$i] = $exp[1];
}
for($i=1; $i<=count($x); $i++){
$ax[$i] = $x[$i]*$width/$coloane;
$bx[$i] = $y[$i]*$height/$linii;
$bx[$i] = $height-$bx[$i];
imagestring ($img,5,$ax[$i],$bx[$i]+1,'('.$x[$i].';'.$y[$i].')',$textcol);
}
for($i=1; $i<count($bx); $i++){
imageline ($img,$ax[$i],$bx[$i],$ax[$i+1],$bx[$i+1],$linecol);
}




imagejpeg ($img, '', 100);
?>

Utilizare:

1) In array-ul $puncte, exact la inceput sunt date punctele de coordonate x si y. De acolo puteti adauga,sterge,modifica puncte/coordonate.

2) Grid-urile verticale si orizontale sunt intre //forsxn sau //forsyn pentru cei care nu vor sa le vada.

3) Inaltimea si latimea 100% modificabile fara sa denatureze valorile graficului.

4) $linii, $coloane = numarul de linii si de coloane care sa delimiteze graficul (schimbati valorile si veti intelege)

5)

ImageString ($img,5,$ax[$i],$bx[$i]+1,'('.$x[$i].';'.$y[$i].')',$textcol);

este linia care face sa apara pe grafic valorile numerice.. in caz ca vreti sau nu sa va apara, o stergeti.

Link to comment
Share on other sites

Ok... Am facut si o interfata pentru generarea graficului. Preview:

http://crs12decoder.comoj.com/interfata.php (va rog nu abuzati in vreun fel)

Interfata aici:


<?php
session_start();

if(!isset($_SESSION['linii'])){
$_SESSION['linii'] = 10;
$_SESSION['coloane'] = 20;
$_SESSION['height'] = 250;
$_SESSION['width'] = 600;
}
if(!isset($_SESSION['in']) || strlen($_SESSION['in'] <3)){
$_SESSION['in'] = '3,2
5,6
8,4.21';
}
$in='3,2;5,6;8,4.21';
$dimensiuni = '10,20,250,600';
if(isset($_POST['input'])){
$_SESSION['in'] = $_POST['input'];
$exp=explode("\n", $_POST['input']);
$in='';
for($i=0; $i<count($exp); $i++){
if(strlen($exp[$i]) > 2){
$in=$in.$exp[$i].';';
}
}
$in=substr($in, 0, strlen($in)-1);
$_SESSION['linii'] = $_POST['linii'];
$_SESSION['coloane'] = $_POST['coloane'];
$_SESSION['height'] = $_POST['inaltime'];
$_SESSION['width'] = $_POST['latime'];
$dimensiuni = $_SESSION['linii'].','.$_SESSION['coloane'].','.$_SESSION['height'].','.$_SESSION['width'];
}

echo '<img src="graph.php?in='.$in.'&dimensiuni='.$dimensiuni.'"></img>';
?>
<br>
<table border="1">
<th>Punctele de<br>coordonate x,y</th>
<th>Dimensiuni</th>
<th>Intrebari?</th>
<tr><td><center>
<form action="" method="POST">
<textarea rows="4" cols="5" name="input">
<?php
echo $_SESSION['in'];
?>
</textarea><br>
<input type="submit" name="submit" value="Genereaza">
</td><td>
<table border="0">
<tr><td>Inaltime:</td><td><input type="text" name="inaltime" size="2" value="<?php echo $_SESSION['height']; ?>"> px</td></tr>
<tr><td>Latime:</td><td><input type="text" name="latime" size="2" value="<?php echo $_SESSION['width']; ?>"> px</td></tr>
<tr><td>Linii:</td><td><input type="text" name="linii" size="2" value="<?php echo $_SESSION['linii']; ?>"></td></tr>
<tr><td>Coloane:</td><td><input type="text" name="coloane" size="2" value="<?php echo $_SESSION['coloane']; ?>"></td></tr>

</table>
</td><td valign="top">
*Coordonatele x sau y pot fi scrise cu zecimale despartite prin punct. <b>Ex: 4.2 sau 8.7</b><br>
*Inaltimea, si latimea reprezinta dimensiunile graficului masurate in pixeli<br>
*Liniile si coloanele reprezinta numarul de delimitari in functie de dimensiune (modificati si veti intelege)
</td>
</form></center>
</tr>
</table>

Graficul aici


<?php

if(isset($_GET['in'])){
$in = $_GET['in'];
$exp = explode(';', $in);
for($i=0; $i<count($exp); $i++){
$puncte[$i+1] = $exp[$i];
}


$linii = 10;
$coloane = 20;
$height = 250;
$width = 600;

if(isset($_GET['dimensiuni'])){
$exp = explode(',',$_GET['dimensiuni']);
$linii = $exp[0];
$coloane = $exp[1];
$height = $exp[2];
$width = $exp[3];
}

header ("Content-type: image/jpeg");

$img = imagecreate ($width,$height);
$fond = imagecolorallocate ($img,211,211,211);
$col = imagecolorallocate ($img,0,0,0);
$linecol = imagecolorallocate ($img,82,10,26);
$textcol = imagecolorallocate ($img,0,34,102);

imageline ($img,0,$width,0,0,$col);
imageline ($img,$width,0,0,0,$col);
imageline ($img,0,$height-1,$width,$height-1,$col);
imageline ($img,$width-1,0,$width-1,$height,$col);

//forsyn
$ay=0;
for($i=0; $i<=$linii; $i++){
$ay=$ay+$height/$linii;
imageline ($img,0,$ay,$width,$ay,$col);
}
//forsyn

//forsxn
$ay=0;
for($i=0; $i<=$coloane; $i++){
$ay=$ay+$width/$coloane;
imageline ($img,$ay,0,$ay,$height,$col);
}
//forsxn

for($i=1; $i<=count($puncte); $i++){
$exp = explode(',', $puncte[$i]);
$x[$i] = $exp[0];
$y[$i] = $exp[1];
}
for($i=1; $i<=count($x); $i++){
$ax[$i] = $x[$i]*$width/$coloane;
$bx[$i] = $y[$i]*$height/$linii;
$bx[$i] = $height-$bx[$i];
imagestring ($img,5,$ax[$i],$bx[$i]+1,'('.$x[$i].';'.$y[$i].')',$textcol);
}
for($i=1; $i<count($bx); $i++){
imageline ($img,$ax[$i],$bx[$i],$ax[$i+1],$bx[$i+1],$linecol);
}




imagejpeg ($img, '', 100);
}
?>

Evident, trebuie ca fisierul cu graficul sa aiba denumirea graph.php

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...