Als ik onderstaande pagina test in een php pagina op de site werkt hij uitstekend, als ik hem op joomla plaats binnen {source} tags, geeft hij allemaal rare tekentjes
<?php
// PHP Graph - find updates and more at: http://ift.tt/1L7HzAv
$loginstring = "";
$host = "localhost";
$database = "algen23_crowd";
$user="algen23";
$password = "axolotl3#";
$t = @mysql_connect ($host, $user, $password) ;
//mysql_select_db( $database )or die('connection');
//$res=mysql_query($select);
//$optieA=7000;
//while($row = mysql_fetch_array($select)){
// $optieA=$optieA + $row[$'bedragbetaald'];
// }
$seed = 500;
// for the demo:
$amounts = Array(
"Optie A: "=> 60,
"Optie B: "=>rand(0,$seed),
"Optie C: "=>rand(0,$seed),
"Optie D: "=>rand(0,$seed),
"Optie E: "=>rand(0,$seed),
"TOTAAL : "=>rand(0,$seed),
);
// or for 'real' use:
// $amounts = $_SESSION['amounts'];
// where the page with the <img src="graph.php"> sets up the $amounts array and stores in the session.
// sort amounts (lowest>highest)
//if(rand(0,1)>0.5) {
// asort($amounts);
//}
// user defined vars:
// all measurements are in pixels
// any less than 12 will cut off the text
$bar_height = 50;
// how many pixels to leave between bars (vertically)
$bar_spacing = 50;
// set grid spacing, any less than 25 will fudge the text. min 50 is preferable.
$valid_spacings = Array(50,100,150);
$grid_space = $valid_spacings[rand(0,count($valid_spacings)-1)];
// amount of space to give for bar titles (horizontally)
$bar_title_space = 70;
// (optional) title of graph
$graph_title = "Resultaat.";
// vertical space to leave for title
$graph_title_space = 40;
// vertical space to leave for footer
$graph_footer_space = 20;
// colour of bars
// 0=red, 1=green, 2=blue, 3=random
$bar_colour = 2;
// end setup
// calculate required width and height of image
$pic_width = $bar_title_space+max($amounts)+($grid_space*1.5);
$pic_height = ($bar_height+$bar_spacing+2)*sizeof($amounts)+20+$ graph_title_space+$graph_footer_space;
// create image
$pic = ImageCreate($pic_width+1,$pic_height+1);
// allocate colours
$white = ImageColorAllocate($pic,255,255,255);
$grey = ImageColorAllocate($pic,200,200,200);
$lt_grey = ImageColorAllocate($pic,210,210,210);
$black = ImageColorAllocate($pic,0,0,0);
// fill background of image with white
ImageFilledRectangle($pic,0,0,$pic_width,$pic_heig ht,$white);
// draw graph title
ImageString($pic,5,($pic_width/2)-(strlen($graph_title)*5),0,$graph_title,$black);
// draw graph footer
ImageString($pic, 2,($pic_width/2)-(strlen($graph_footer)*3),$pic_height-$graph_footer_space, $graph_footer, $grey);
// draw grid markers
for($x_axis=$bar_title_space ; ($x_axis-$bar_title_space)<max($amounts)+$grid_space ; $x_axis+=$grid_space) {
// draw vertical grid marker
ImageLine($pic,$x_axis,$graph_title_space,$x_axis, $pic_height-$graph_footer_space,$grey);
// draw horizontal line above grid numbers
ImageLine($pic,$x_axis,($pic_height-$graph_footer_space-25),$x_axis-($bar_title_space+$grid_space),($pic_height-$graph_footer_space-25),$grey);
// draw grid numbers
ImageString($pic, 3, $x_axis+5, ($pic_height-$graph_footer_space-20), $x_axis-($bar_title_space), $black);
}
// draw bars
$y_axis=$graph_title_space;
if($bar_colour!=3) {
// for a nice smooth fade of colour.
$col = 180;
$decrement = intval($col/count($amounts));
}
foreach($amounts as $key=>$amount) {
// write the bar title
ImageString($pic, 2, ($bar_title_space-(strlen($key)*6)), $y_axis, $key, $black);
// allocate a colour for this bar
if($bar_colour==3) {
// random colour
$tempCol = ImageColorAllocate($pic,rand(50,200),rand(50,200), rand(50,200));
} else {
$col -= $decrement;
if($bar_colour==0) {
// faded red
$tempCol = ImageColorAllocate($pic,255,$col,$col);
} else if($bar_colour==1) {
// faded green
// 200 because green just looks too bright otherwise
$tempCol = ImageColorAllocate($pic,$col,200,$col);
} else if($bar_colour==2) {
// faded blue
$tempCol = ImageColorAllocate($pic,$col,$col,255);
}
}
// draw the bar
ImageFilledRectangle($pic,($bar_title_space+1),$y_ axis,$amount+$bar_title_space,($y_axis+$bar_height ),$tempCol);
if(($amount)<15) {
// if it's a tiny amount, write the amount outside the bar in black
ImageString($pic, 2, ($amount+3)+$bar_title_space, $y_axis, $amount, $black);
} else {
// or if over 20, write the amount inside the bar in white
// the strlen stuff is to ensure number is aligned with the end of the bar. works quite well, too.
ImageString($pic, 2, ($amount-(strlen($amount)*6))+$bar_title_space, $y_axis, $amount, $white);
}
// move down
$y_axis+=($bar_spacing+1)+$bar_height;
}
header("Content-type: image/png");
// output image
ImagePNG($pic);
// remove image from memory
ImageDestroy($pic);
?>
<?php
// PHP Graph - find updates and more at: http://ift.tt/1L7HzAv
$loginstring = "";
$host = "localhost";
$database = "algen23_crowd";
$user="algen23";
$password = "axolotl3#";
$t = @mysql_connect ($host, $user, $password) ;
//mysql_select_db( $database )or die('connection');
//$res=mysql_query($select);
//$optieA=7000;
//while($row = mysql_fetch_array($select)){
// $optieA=$optieA + $row[$'bedragbetaald'];
// }
$seed = 500;
// for the demo:
$amounts = Array(
"Optie A: "=> 60,
"Optie B: "=>rand(0,$seed),
"Optie C: "=>rand(0,$seed),
"Optie D: "=>rand(0,$seed),
"Optie E: "=>rand(0,$seed),
"TOTAAL : "=>rand(0,$seed),
);
// or for 'real' use:
// $amounts = $_SESSION['amounts'];
// where the page with the <img src="graph.php"> sets up the $amounts array and stores in the session.
// sort amounts (lowest>highest)
//if(rand(0,1)>0.5) {
// asort($amounts);
//}
// user defined vars:
// all measurements are in pixels
// any less than 12 will cut off the text
$bar_height = 50;
// how many pixels to leave between bars (vertically)
$bar_spacing = 50;
// set grid spacing, any less than 25 will fudge the text. min 50 is preferable.
$valid_spacings = Array(50,100,150);
$grid_space = $valid_spacings[rand(0,count($valid_spacings)-1)];
// amount of space to give for bar titles (horizontally)
$bar_title_space = 70;
// (optional) title of graph
$graph_title = "Resultaat.";
// vertical space to leave for title
$graph_title_space = 40;
// vertical space to leave for footer
$graph_footer_space = 20;
// colour of bars
// 0=red, 1=green, 2=blue, 3=random
$bar_colour = 2;
// end setup
// calculate required width and height of image
$pic_width = $bar_title_space+max($amounts)+($grid_space*1.5);
$pic_height = ($bar_height+$bar_spacing+2)*sizeof($amounts)+20+$ graph_title_space+$graph_footer_space;
// create image
$pic = ImageCreate($pic_width+1,$pic_height+1);
// allocate colours
$white = ImageColorAllocate($pic,255,255,255);
$grey = ImageColorAllocate($pic,200,200,200);
$lt_grey = ImageColorAllocate($pic,210,210,210);
$black = ImageColorAllocate($pic,0,0,0);
// fill background of image with white
ImageFilledRectangle($pic,0,0,$pic_width,$pic_heig ht,$white);
// draw graph title
ImageString($pic,5,($pic_width/2)-(strlen($graph_title)*5),0,$graph_title,$black);
// draw graph footer
ImageString($pic, 2,($pic_width/2)-(strlen($graph_footer)*3),$pic_height-$graph_footer_space, $graph_footer, $grey);
// draw grid markers
for($x_axis=$bar_title_space ; ($x_axis-$bar_title_space)<max($amounts)+$grid_space ; $x_axis+=$grid_space) {
// draw vertical grid marker
ImageLine($pic,$x_axis,$graph_title_space,$x_axis, $pic_height-$graph_footer_space,$grey);
// draw horizontal line above grid numbers
ImageLine($pic,$x_axis,($pic_height-$graph_footer_space-25),$x_axis-($bar_title_space+$grid_space),($pic_height-$graph_footer_space-25),$grey);
// draw grid numbers
ImageString($pic, 3, $x_axis+5, ($pic_height-$graph_footer_space-20), $x_axis-($bar_title_space), $black);
}
// draw bars
$y_axis=$graph_title_space;
if($bar_colour!=3) {
// for a nice smooth fade of colour.
$col = 180;
$decrement = intval($col/count($amounts));
}
foreach($amounts as $key=>$amount) {
// write the bar title
ImageString($pic, 2, ($bar_title_space-(strlen($key)*6)), $y_axis, $key, $black);
// allocate a colour for this bar
if($bar_colour==3) {
// random colour
$tempCol = ImageColorAllocate($pic,rand(50,200),rand(50,200), rand(50,200));
} else {
$col -= $decrement;
if($bar_colour==0) {
// faded red
$tempCol = ImageColorAllocate($pic,255,$col,$col);
} else if($bar_colour==1) {
// faded green
// 200 because green just looks too bright otherwise
$tempCol = ImageColorAllocate($pic,$col,200,$col);
} else if($bar_colour==2) {
// faded blue
$tempCol = ImageColorAllocate($pic,$col,$col,255);
}
}
// draw the bar
ImageFilledRectangle($pic,($bar_title_space+1),$y_ axis,$amount+$bar_title_space,($y_axis+$bar_height ),$tempCol);
if(($amount)<15) {
// if it's a tiny amount, write the amount outside the bar in black
ImageString($pic, 2, ($amount+3)+$bar_title_space, $y_axis, $amount, $black);
} else {
// or if over 20, write the amount inside the bar in white
// the strlen stuff is to ensure number is aligned with the end of the bar. works quite well, too.
ImageString($pic, 2, ($amount-(strlen($amount)*6))+$bar_title_space, $y_axis, $amount, $white);
}
// move down
$y_axis+=($bar_spacing+1)+$bar_height;
}
header("Content-type: image/png");
// output image
ImagePNG($pic);
// remove image from memory
ImageDestroy($pic);
?>
php pagina die buiten joomla goed werkt, werkt niet in joomla