Ik heb een functie die een grafiek aanmaakt (niet zo bijzonder verder, hij werkt en maakt de grafiek ook daadwerkelijk aan, dus scroll hier voorbij):
Als ik op een LEGE pagina alleen neerzetPHP Code:
function create_graph($value, $date){
if(count($value)!=count($date)){
// The number of values in $values is not the same as in $date, ERROR.
return 'Error';
exit;
}
$array_count = count($value);
// Delete all 'NULL' records from the arrays. *****************************
for($i=0; $i<$array_count; $i++){
if($value[$i]==NULL){
unset($value[$i]);
}
if($date[$i]==NULL){
unset($date[$i]);
}
}
$array_count = count($value);
$image_width = 300;
$image_height = 360;
$graph_size = 250;
$free_space_width = $image_width - $graph_size;
$free_space_height = $image_height - $graph_size;
$image = imagecreate($image_width, $image_height);
$color_white = imagecolorallocate($image, 255, 255, 255);
$color_grey = imagecolorallocate($image, 192, 192, 192);
$color_blue = imagecolorallocate($image, 0, 148, 218);
$color_black = imagecolorallocate($image, 0, 0, 0);
// Create the rectangle around the graph (outer lines). *******************
imagerectangle($image, $free_space_width, 1, $image_width-1, $image_height-$free_space_height, $color_black);
// Create the grid lines. *************************************************
for ($i=1; $i<$array_count-1; $i++){
$grid_break = $graph_size / ($array_count-1); // Create a grid line every graph_width / (the number of values in the array-1) pixels.
imageline($image, $i*$grid_break+$free_space_width, 2, $i*$grid_break+$free_space_width, $image_height-$free_space_height-1, $color_grey); // Y-axis
imageline($image, $free_space_width+1, $i*$grid_break, $image_width-2, $i*$grid_break, $color_grey); // X-axis
}
// Set the Y-axis legend. *************************************************
if(min($value)==NULL){
$lowest_value=0; // If there is a NULL value in the value array, make the lowest number 0 instead of NULL.
}
imagestringup($image, 4, 1, $graph_size/2, "Weight", $color_black); // Y-axis name
for($i=0; $i<$array_count; $i++){
// The Y-axis has $array_count values, thus the average, that should be displayed at each grid line, should increase with max($values)/$array_count every time, starting at min($values).
$y_value = number_format(max($value)/$array_count, 1, ".", " ");
$y_value = ($i+1) * $y_value;
if($i==0){
// The first number on the Y-axis should always be 0.
$y_value = 0;
}
if($i==$array_count-1){
// The last number on the Y-axis should always be max($value)
$y_value = max($value);
}
imagestring($image, 3, $free_space_width-20, $graph_size-($grid_break*$i), $y_value, $color_black);
}
// Set the X-axis legend. *************************************************
imagestring($image, 4, $image_width/2, $image_height-20, "Date", $color_black); // X-axis name
for($i=0; $i<$array_count; $i++){
$text_to_left = 5; // Number of pixels the text should be shifted to the left from its origin.
if($i==($array_count-1)){
$text_to_left = 15; // The last text string that is going to be printed should be shifted slightly more to the left, so that it doesn't get outside the image's borders.
}
imagestringup($image, 3, $i*$grid_break+$free_space_width-$text_to_left, $image_height-32, $date[$i], $color_black); // Set the highest number in the value array to be the highest number on the y-axis.
}
// Create the graph. ******************************************************
for($i=0; $i<$array_count; $i++){
// For each value in the array, determine the y-value in the graph (relatively).
$y_height[$i] = $value[$i]/max($value);
$y_height[$i] = $y_height[$i]*$graph_size;
}
for ($i=0; $i<$array_count; $i++){
imageline($image, $free_space_width+($i*$grid_break), $graph_size-$y_height[$i], $free_space_width+(($i+1)*$grid_break), $graph_size-$y_height[$i+1], $color_blue);
imagerectangle($image, $free_space_width+($i*$grid_break)-1, $graph_size-$y_height[$i]-1, $free_space_width+($i*$grid_break)+1, $graph_size-$y_height[$i]+1, $color_blue);
}
header("Content-type: image/png");
imagejpeg($image);
imagedestroy($image);
}
create_graph(waardes)
(voor de liefhebbers die willen testen, hier de code):
komt er een heel mooi grafiekje uitrollen.PHP Code:
$value=array(1, 2, 4, 4, 9, 6, 7, 8);
$date=array("10-10-2010", "10-10-2010", "10-10-2010", "10-10-2010", "10-10-2010", "10-10-2010", "10-10-2010", "10-10-2010");
create_graph($value,$date);
Zodra ik hem echter als plaatje wil gebruiken op een pagina van mn site, krijg ik een volledig witte pagina waarop staat: "De afbeelding ... kan niet worden weergegeven, omdat deze fouten bevat". De betreffende pagina start met ob_start() en eindigt met ob_end_flush(). Als ik deze twee regels weg haal, krijg ik wel de normale pagina te zien, met een error:
Warning: Cannot modify header information - headers already sent by (output started at C:\...\php_includes\header.inc.php:43) in C:\xampp\htdocs\iProgrS\function_graph.php on line 104
�����JFIF���������>CREATOR: gd-jpeg v1.0 (using IJG JPEG v70), default quality ���C� $.' ",#(7),01444'9=82<.342���C 2!!22222222222222222222222222222222222222222222222 222���
Ik denk dat het aan een header probleem oid ligt, maar ik zou niet weten hoe ik het op moet lossen. Weet iemand wellicht wat te doen?
- impagepng - image error bij laden
-
14-10-2010, 22:11 #1
- Berichten
- 36
- Lid sinds
- 15 Jaar
impagepng - image error bij laden
-
-
14-10-2010, 22:17 #2
- Berichten
- 122
- Lid sinds
- 17 Jaar
Re: impagepng - image error bij laden
je roept nu de functie aan in je code nadat je je headers al hebt verzonden. de oplossing: maak een nieuwe php-file aan waarin je de functie aanroept en include die file in de code van jouw pagina waar je het plaatje wilt zien.
-
14-10-2010, 22:19 #3
- Berichten
- 36
- Lid sinds
- 15 Jaar
Re: impagepng - image error bij laden
Heb ik =).
De functie staat in function_graph.php. Deze staat geinclude in account.php. Account.php include ook header.inc.php. De ob_flush staat in account.php, boven de include van header.inc.php.
In account.php roep ik dus de functie uit function_graph.php aan. Het lukt niet als ik <img src="function_graph()"> doe, ook niet als ik los function_graph(); doe.
*Edit: function_graph() moet create_graph() zijn :pLaatst aangepast door Stephan G. : 14-10-2010 om 22:24
Plaats een
- + Advertentie
- + Onderwerp
Marktplaats
Webmasterforum
- Websites algemeen
- Sitechecks
- Marketing
- Domeinen algemeen
- Waardebepaling
- CMS
- Wordpress
- Joomla
- Magento
- Google algemeen
- SEO
- Analytics
- Adsense
- Adwords
- HTML / XHTML
- CSS
- Programmeren
- PHP
- Javascript
- JQuery
- MySQL
- Ondernemen algemeen
- Belastingen
- Juridisch
- Grafisch ontwerp
- Hosting Algemeen
- Hardware Info
- Offtopic