Below is my coding:
can someone help me on the array part, where i only want the x-label with value will be display. in other words if no value the x-label will not be displayed for that data.
tq.
<?
require ("../core.php"
$link_id = db_connect($user_dbname);
//menu_header_student_profile();
header("Content-type: image/gif" // or "Content-type: image/png"
$query2 = "SELECT * FROM lkp_country";
$result2 = pg_exec($query2);
$total2 = pg_numrows($result2);
while ($row = pg_fetch_array($result2)) {
$arrsu[] = $row["ctry_code"];
$arrsu2[] = $row["ctry_desc"];
}
$strData = '$data=array(';
for($i=0; $i<$total2; $i++) {
$query = "SELECT * FROM adm_student_registered
INNER JOIN adm_student_profile ON adm_student_registered.sreg_stud_profileid = adm_student_profile.stud_profileid
WHERE stud_country = '$arrsu[$i]' ";
$result = pg_exec($query);
$total = pg_numrows($result);
$rows = pg_fetch_array($result);
$strData .= "\"" . " $arrsu2[$i]" . "\"" . ' => ' . $total . ',';
}
$strData .= ');';
eval($strData);
// Here we begin the graph
$width = 480;
$height = 450;
$image = imagecreate($width, $height);
// colors
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$navy = imagecolorallocate($image, 0x00, 0x00, 0x80);
$black = imagecolorallocate($image, 0x00, 0x00, 0x00);
$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
// layout
$maxval = max($data);
$nval = sizeof($data);
$vmargin = 40; // top (bottom) vertical margin for title (x-labels)
$hmargin = 70; // left horizontal margin for y-labels
$base = floor(($width - $hmargin) / $nval); // distance between columns
$ysize = $height - 2 * $vmargin; // y-size of plot
$xsize = $nval * $base; // x-size of plot
// title
$titlefont = 3;
$title = "Total Student For Each Country";
//echo "<img src='/button/bmi.jpg' width='36' height='40'></A>\n";
$txtsz = imagefontwidth($titlefont) * strlen($title); // pixel-width of title
$xpos = (int)($hmargin + ($xsize - $txtsz)/2); // center the title
$xpos = max(1, $xpos); // force positive coordinates
$ypos = 3; // distance from top
imagestring($image, $titlefont, $xpos, $ypos, $title , $black);
// y labels and grid lines
$labelfont = 2;
$ngrid = 4; // number of grid lines
$dydat = $maxval / $ngrid; // data units between grid lines
$dypix = $ysize / ($ngrid + 1); // pixels between grid lines
for ($i = 0; $i <= ($ngrid + 1); $i++) {
// iterate over y ticks
// height of grid line in units of data
$ydat = (int)($i * $dydat);
// height of grid line in pixels
$ypos = $vmargin + $ysize - (int)($i*$dypix);
$txtsz = imagefontwidth($labelfont) * strlen($ydat); // pixel-width of label
$txtht = imagefontheight($labelfont); // pixel-height of label
$xpos = (int)(($hmargin - $txtsz) / 2);
$xpos = max(1, $xpos);
imagestring($image, $labelfont, $xpos,
$ypos - (int)($txtht/2), $ydat, $black);
if (!($i == 0) && !($i > $ngrid)) {
imageline($image, $hmargin - 3,
$ypos, $hmargin + $xsize, $ypos, $gray);
// don't draw at Y=0 and top
}
}
// columns and x labels
$padding = 3; // half of spacing between columns
$yscale = $ysize / (($ngrid+1) * $dydat); // pixels per data unit
for ($i = 0; list($xval, $yval) = each($data); $i++) {
// vertical columns
$ymax = $vmargin + $ysize;
$ymin = $ymax - (int)($yval*$yscale);
$xmax = $hmargin + ($i+1)*$base - $padding;
$xmin = $hmargin + $i*$base + $padding;
imagefilledrectangle($image, $xmin, $ymin, $xmax, $ymax, $navy);
// x labels
$txtsz = imagefontwidth($labelfont) * strlen($xval);
$xpos = $xmin + (int)(($base - $txtsz) / 2);
$xpos = max($xmin, $xpos);
$ypos = $ymax + 3; // distance from x axis
imagestring($image, $labelfont, $xpos, $ypos, $xval, $black);
}
// plot frame
imagerectangle($image, $hmargin, $vmargin,
$hmargin + $xsize, $vmargin + $ysize, $black);
// flush image
//header("Content-type: image/gif" // or "Content-type: image/png"
imagegif($image); // or imagepng($image)
imagedestroy($image);
?>
can someone help me on the array part, where i only want the x-label with value will be display. in other words if no value the x-label will not be displayed for that data.
tq.
<?
require ("../core.php"
$link_id = db_connect($user_dbname);
//menu_header_student_profile();
header("Content-type: image/gif" // or "Content-type: image/png"
$query2 = "SELECT * FROM lkp_country";
$result2 = pg_exec($query2);
$total2 = pg_numrows($result2);
while ($row = pg_fetch_array($result2)) {
$arrsu[] = $row["ctry_code"];
$arrsu2[] = $row["ctry_desc"];
}
$strData = '$data=array(';
for($i=0; $i<$total2; $i++) {
$query = "SELECT * FROM adm_student_registered
INNER JOIN adm_student_profile ON adm_student_registered.sreg_stud_profileid = adm_student_profile.stud_profileid
WHERE stud_country = '$arrsu[$i]' ";
$result = pg_exec($query);
$total = pg_numrows($result);
$rows = pg_fetch_array($result);
$strData .= "\"" . " $arrsu2[$i]" . "\"" . ' => ' . $total . ',';
}
$strData .= ');';
eval($strData);
// Here we begin the graph
$width = 480;
$height = 450;
$image = imagecreate($width, $height);
// colors
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$navy = imagecolorallocate($image, 0x00, 0x00, 0x80);
$black = imagecolorallocate($image, 0x00, 0x00, 0x00);
$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
// layout
$maxval = max($data);
$nval = sizeof($data);
$vmargin = 40; // top (bottom) vertical margin for title (x-labels)
$hmargin = 70; // left horizontal margin for y-labels
$base = floor(($width - $hmargin) / $nval); // distance between columns
$ysize = $height - 2 * $vmargin; // y-size of plot
$xsize = $nval * $base; // x-size of plot
// title
$titlefont = 3;
$title = "Total Student For Each Country";
//echo "<img src='/button/bmi.jpg' width='36' height='40'></A>\n";
$txtsz = imagefontwidth($titlefont) * strlen($title); // pixel-width of title
$xpos = (int)($hmargin + ($xsize - $txtsz)/2); // center the title
$xpos = max(1, $xpos); // force positive coordinates
$ypos = 3; // distance from top
imagestring($image, $titlefont, $xpos, $ypos, $title , $black);
// y labels and grid lines
$labelfont = 2;
$ngrid = 4; // number of grid lines
$dydat = $maxval / $ngrid; // data units between grid lines
$dypix = $ysize / ($ngrid + 1); // pixels between grid lines
for ($i = 0; $i <= ($ngrid + 1); $i++) {
// iterate over y ticks
// height of grid line in units of data
$ydat = (int)($i * $dydat);
// height of grid line in pixels
$ypos = $vmargin + $ysize - (int)($i*$dypix);
$txtsz = imagefontwidth($labelfont) * strlen($ydat); // pixel-width of label
$txtht = imagefontheight($labelfont); // pixel-height of label
$xpos = (int)(($hmargin - $txtsz) / 2);
$xpos = max(1, $xpos);
imagestring($image, $labelfont, $xpos,
$ypos - (int)($txtht/2), $ydat, $black);
if (!($i == 0) && !($i > $ngrid)) {
imageline($image, $hmargin - 3,
$ypos, $hmargin + $xsize, $ypos, $gray);
// don't draw at Y=0 and top
}
}
// columns and x labels
$padding = 3; // half of spacing between columns
$yscale = $ysize / (($ngrid+1) * $dydat); // pixels per data unit
for ($i = 0; list($xval, $yval) = each($data); $i++) {
// vertical columns
$ymax = $vmargin + $ysize;
$ymin = $ymax - (int)($yval*$yscale);
$xmax = $hmargin + ($i+1)*$base - $padding;
$xmin = $hmargin + $i*$base + $padding;
imagefilledrectangle($image, $xmin, $ymin, $xmax, $ymax, $navy);
// x labels
$txtsz = imagefontwidth($labelfont) * strlen($xval);
$xpos = $xmin + (int)(($base - $txtsz) / 2);
$xpos = max($xmin, $xpos);
$ypos = $ymax + 3; // distance from x axis
imagestring($image, $labelfont, $xpos, $ypos, $xval, $black);
}
// plot frame
imagerectangle($image, $hmargin, $vmargin,
$hmargin + $xsize, $vmargin + $ysize, $black);
// flush image
//header("Content-type: image/gif" // or "Content-type: image/png"
imagegif($image); // or imagepng($image)
imagedestroy($image);
?>