Wer kann mir mal ein kleines Script zeigen um eine Kuchengrafik zuerstellen. Habe dazu leider nichts gefunden.
[GD] Kuchengrafik erstellen
Einklappen
X
-
[GD] Kuchengrafik erstellen
*winks*
Gilbert
------------------------------------------------
Hilfe für eine Vielzahl von Problemen!!!
http://www.1st-rootserver.de/
Stichworte: -
-
guckst du hier in die user-notes
http://de2.php.net/manual/de/functio...efilledarc.php
EDIT:
mit link gehts besser
-
Hilft mir nicht wirklich, hast du da ein Beispiel Code?*winks*
Gilbert
------------------------------------------------
Hilfe für eine Vielzahl von Problemen!!!
http://www.1st-rootserver.de/
Kommentar
-
habs extra ohne funktion und schleife geschrieben, ich denke solltePHP-Code:$wert1 = 30; // je in %
$wert2 = 50;
$wert3 = 20;
$winkel1 = round(360*$wert1/100);
$winkel2 = round(360*$wert2/100);
$winkel3 = round(360*$wert3/100);
$start_a1 = 0;
$start_a2 = $start_a1 + $winkel1;
$start_b1 = $start_a2;
$start_b2 = $start_b1 + $winkel2;
$start_c1 = $start_b2;
$start_c2 = $start_c1 + $winkel3;
// oder
$start_c2 = 360;
// ^^ muss natürlich in eine fkt/schleife
$width = 100;
$height = 100;
$image = imagecreate($width, $height);
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
$navy = imagecolorallocate($image, 0x00, 0x00, 0x80);
$red = imagecolorallocate($image, 0xFF, 0x00, 0x00);
//imagefilledarc ($image, mitte_x, mitte_y, durchmesser_x, durchmesser_y, startwinkel,endwinkel, farbe, IMG_ARC_FILL);
imagefilledarc ($image, 50, 50, 100, 100,$start_a1, $start_a2, $navy, IMG_ARC_FILL);
imagefilledarc ($image, 50, 50, 100, 100, $start_b1, $start_b2, $gray, IMG_ARC_FILL);
imagefilledarc ($image, 50, 50, 100, 100, $start_c1, $start_c2, $red, IMG_ARC_FILL);
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
logisch sein.
Kommentar
-
Gut muss erstmal auf GD2 hoch, dann kann ich weiter sehen.*winks*
Gilbert
------------------------------------------------
Hilfe für eine Vielzahl von Problemen!!!
http://www.1st-rootserver.de/
Kommentar
-
Kannst du das mal Testen?
PHP-Code:<?
$wert1 = 30; // je in %
$wert2 = 50;
$wert3 = 20;
$winkel1 = round(360*$wert1/100);
$winkel2 = round(360*$wert2/100);
$winkel3 = round(360*$wert3/100);
$start_a1 = 0;
$start_a2 = $start_a1 + $winkel1;
$start_b1 = $start_a2;
$start_b2 = $start_b1 + $winkel2;
$start_c1 = $start_b2;
$start_c2 = $start_c1 + $winkel3;
// oder
$start_c2 = 360;
// ^^ muss natürlich in eine fkt/schleife
// create image
$width = 100;
$height = 100;
$image = imagecreate($width, $height);
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
$darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
$navy = imagecolorallocate($image, 0x00, 0x00, 0x80);
$darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50);
$red = imagecolorallocate($image, 0xFF, 0x00, 0x00);
$darkred = imagecolorallocate($image, 0x90, 0x00, 0x00);
for ($i = 60;$i > 50;$i--)
{
imagefilledarc ($image, 50, $i, 100, 50, $start_a1, $start_a2, $darknavy, IMG_ARC_PIE);
imagefilledarc ($image, 50, $i, 100, 50, $start_b1, $start_b2, $darkgray, IMG_ARC_PIE);
imagefilledarc ($image, 50, $i, 100, 50, $start_c1, $start_c2, $darkred, IMG_ARC_PIE);
}
imagefilledarc ($image, 50, 50, 100, 100,$start_a1, $start_a2, $navy, IMG_ARC_FILL);
imagefilledarc ($image, 50, 50, 100, 100, $start_b1, $start_b2, $gray, IMG_ARC_FILL);
imagefilledarc ($image, 50, 50, 100, 100, $start_c1, $start_c2, $red, IMG_ARC_FILL);
// flush image
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
?>*winks*
Gilbert
------------------------------------------------
Hilfe für eine Vielzahl von Problemen!!!
http://www.1st-rootserver.de/
Kommentar
-
Danke. 3D sieht glaube ich besser aus, oder?*winks*
Gilbert
------------------------------------------------
Hilfe für eine Vielzahl von Problemen!!!
http://www.1st-rootserver.de/
Kommentar
-
irgendwo war der wurm drin, so gehts aber:
online unter dem link den ich dir geschickt habe.PHP-Code:$width = 100;
$height = 100;
$image = imagecreate($width, $height);
$wert1 = 30; // je in %
$wert2 = 50;
$wert3 = 20;
$winkel1 = round(360*$wert1/100);
$winkel2 = round(360*$wert2/100);
$winkel3 = round(360*$wert3/100);
$start_a1 = 0;
$start_a2 = $start_a1 + $winkel1;
$start_b1 = $start_a2;
$start_b2 = $start_b1 + $winkel2;
$start_c1 = $start_b2;
$start_c2 = $start_c1 + $winkel3;
// oder
$start_c2 = 360;
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
$darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
$navy = imagecolorallocate($image, 0x00, 0x00, 0x80);
$darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50);
$red = imagecolorallocate($image, 0xFF, 0x00, 0x00);
$darkred = imagecolorallocate($image, 0x90, 0x00, 0x00);
for ($i = 60;$i > 50;$i--) {
imagefilledarc ($image, 50, $i, 100, 50, $start_a1, $start_a2, $darknavy, IMG_ARC_PIE);
imagefilledarc ($image, 50, $i, 100, 50, $start_b1, $start_b2 , $darkgray, IMG_ARC_PIE);
imagefilledarc ($image, 50, $i, 100, 50, $start_c1, $start_c2 , $darkred, IMG_ARC_PIE);
}
imagefilledarc ($image, 50, 50, 100, 50, $start_a1, $start_a2, $navy, IMG_ARC_PIE);
imagefilledarc ($image, 50, 50, 100, 50, $start_b1, $start_b2 , $gray, IMG_ARC_PIE);
imagefilledarc ($image, 50, 50, 100, 50, $start_c1, $start_c2, $red, IMG_ARC_PIE);
// flush image
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
EDIT:
ah, du hattest schon "gespannt". ich find 3d auch besser. das einzige, was nervt ist das fehlende antialising. könnte man vielleicht beheben indem man das bild 3-4x so gross anlegt wie benötigt und dann auf die endgösse runterrechnet. musst du mal testenZuletzt geändert von Wurzel; 14.07.2003, 17:09.
Kommentar
-
Wie bekommen ich das jetzt mit der GD1.6 hin?*winks*
Gilbert
------------------------------------------------
Hilfe für eine Vielzahl von Problemen!!!
http://www.1st-rootserver.de/
Kommentar
-
ein andere Alternative wäre sicherlich JpGraph, eine Bibliothek mit Unterstützung für alle möglichen Diagramm-Typen.
Kostenlos, erhältlich unter http://www.aditus.nu/jpgraph/
Voraussetzung ist aber mindestens GD 1.8.x und PHP 4.1, man kann nur versuchen ob sich ein 3D-Pie erstellen lässt, eine Testsuite ist enthalten
Kommentar
-
hier ist de grafik zu wurzel´s Post.
@flat_le
Die kann ich leider nicht benutzen, da ich nur <= GD1.6 habeAngehängte Dateien*winks*
Gilbert
------------------------------------------------
Hilfe für eine Vielzahl von Problemen!!!
http://www.1st-rootserver.de/
Kommentar
-
so, das klappt nun auch mit der gd1.6 (hoffentlich). allerdings
NICHT in 3D
:
PHP-Code:// basis parameter definieren
$werte=array("30","50","20"); // prozentwerte
$winkel=array();
$start = array();
$end=array();
// definition der tortenparameter
$diameter = 100;
$radius = $centerX = $centerY = $diameter/2;
// bild anlegen mit weissem hintergrund
$image = imagecreate($diameter, $diameter);
$background = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
// winkel für die einzelnen tortenstücke berechnen
for($i=0;$i<count($werte);$i++)
{
$winkel[] = round(360*$werte[$i]/100);
}
// start/endpositionen für die tortenstücke ermitteln
$start[] = 0;
for($i=0;$i<count($winkel);$i++)
{
$end[] = $start[$i] + $winkel[$i];
if($i< (count($winkel)-1))
{
$start[] = $end[$i];
}
}
// farben definieren, kann/muss man anders lösen => in abhängigkeit zur
// anzahl der werte
$light = array();
$dark = array();
$light[] = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
$dark[] = imagecolorallocate($image, 0x90, 0x90, 0x90);
$light[] = imagecolorallocate($image, 0x00, 0x00, 0x80);
$dark[] = imagecolorallocate($image, 0x00, 0x00, 0x50);
$light[] = imagecolorallocate($image, 0xFF, 0x00, 0x00);
$dark[] = imagecolorallocate($image, 0x90, 0x00, 0x00);
// flächen der einzelnen torten-elemente füllen
// (inspiriert von den user-notes bei php.net => imagearc())
function fill_arc($start, $end, $color) {
global $diameter, $centerX, $centerY, $image, $radius;
imagearc($image, $centerX, $centerY, $diameter, $diameter, $start, $end, $color);
imageline($image, $centerX, $centerY, $centerX + cos(deg2rad($start)) * $radius, $centerY + sin(deg2rad($start)) * $radius , $color);
imageline($image, $centerX, $centerY, $centerX + cos(deg2rad($end)) * $radius , $centerY + sin(deg2rad($end)) * $radius, $color);
imagefill ($image,$centerX + $radius * 0.5 *cos(deg2rad($start+($end-$start)/2)), $centerY + $radius * 0.5 * sin(deg2rad($start+($end-$start)/2)), $color);
}
for($i=0;$i<count($werte);$i++)
{
fill_arc($start[$i], $end[$i], $light[$i]);
}
// raus mit dem bild an den browser
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
Kommentar
-
KNUTSCH
Das hat dich jetzt gewurmt, das das andere Script nicht für die GD1.6 geht. Auf die 3D kann ich auch verzichten.
Frage: weißt du wie ich die Kuchestücke jetzt auch noch Beschriften kann?*winks*
Gilbert
------------------------------------------------
Hilfe für eine Vielzahl von Problemen!!!
http://www.1st-rootserver.de/
Kommentar
-
jupp!Original geschrieben von Wotan
Das hat dich jetzt gewurmt, das das andere Script nicht für die GD1.6 geht. Auf die 3D kann ich auch verzichten.
jetzt mal nicht gierig werdenOriginal geschrieben von Wotan
Frage: weißt du wie ich die Kuchestücke jetzt auch noch Beschriften kann?
gibt dir momentan die koordinaten aus, auf denen der text erscheint. musst du mal nen bischen mit rumspielen, um die exakte position zu ermitteln.PHP-Code:// basis parameter definieren
$werte=array("30","50","20"); // prozentwerte
$winkel=array();
$start = array();
$end=array();
// definition der tortenparameter
$diameter = 100;
$radius = $diameter/2;
$centerX = $centerY = 100;
// bild anlegen mit weissem hintergrund
$image = imagecreate(300,300);
$background = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
// winkel für die einzelnen tortenstücke berechnen
for($i=0;$i<count($werte);$i++)
{
$winkel[] = round(360*$werte[$i]/100);
}
// start/endpositionen für die tortenstücke ermitteln
$start[] = 0;
for($i=0;$i<count($winkel);$i++)
{
$end[] = $start[$i] + $winkel[$i];
if($i< (count($winkel)-1))
{
$start[] = $end[$i];
}
}
// farben definieren, kann/muss man anders lösen => in abhängigkeit zur
// anzahl der werte
$light = array();
$dark = array();
$light[] = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
$dark[] = imagecolorallocate($image, 0x90, 0x90, 0x90);
$light[] = imagecolorallocate($image, 0x00, 0x00, 0x80);
$dark[] = imagecolorallocate($image, 0x00, 0x00, 0x50);
$light[] = imagecolorallocate($image, 0xFF, 0x00, 0x00);
$dark[] = imagecolorallocate($image, 0x90, 0x00, 0x00);
// flächen der einzelnen torten-elemente füllen
// (inspiriert von den user-notes bei php.net => imagearc())
function fill_arc($start, $end, $color,$wert) {
global $diameter, $centerX, $centerY, $image, $radius, $black;
imagearc($image, $centerX, $centerY, $diameter, $diameter, $start, $end, $color);
imageline($image, $centerX, $centerY, $centerX + cos(deg2rad($start)) * $radius, $centerY + sin(deg2rad($start)) * $radius , $color);
imageline($image, $centerX, $centerY, $centerX + cos(deg2rad($end)) * $radius , $centerY + sin(deg2rad($end)) * $radius, $color);
imagefill ($image,$centerX + $radius * 0.5 *cos(deg2rad($start+($end-$start)/2)), $centerY + $radius * 0.5 * sin(deg2rad($start+($end-$start)/2)), $color);
// beschriftung mit dem prozentwert
$text=$wert."%";
$img_x = $centerX + cos(deg2rad($end)) * ($radius+10);
$img_y = $centerY + sin(deg2rad($end)) * ($radius+10);
$text = "x: ".$img_x." | y: ".$img_y; // nur zum testen der coords
ImageTTFText ($image, 10, 0,$img_x, $img_y, $color, "arial.ttf", $text);
}
for($i=0;$i<count($werte);$i++)
{
fill_arc($start[$i], $end[$i], $light[$i], $werte[$i]);
}
// raus mit dem bild an den browser
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
Kommentar

Kommentar