Jump to content

JpGraph display weird things/symbols


wackyflik

Recommended Posts

i've got some weird output like symbols when run these codes. what happened actually??

[code]
<?php
session_start();
if(isset($_SESSION['user'])) {

$dateId = $_GET['id'];

function generateGraph($year, $month){
include('../config_default.php');
include('../jpgraph/src/jpgraph.php'); 
include('../jpgraph/src/jpgraph_bar.php');

$sql = "SELECT f.facultyInitial,
        COUNT(*) AS Total
FROM attendance att
INNER JOIN academic a
ON att.academicNo = a.academicNo
INNER JOIN program p
ON a.programId = p.programId
INNER JOIN faculty f
ON p.facultyId = f.facultyId
WHERE MONTH(att.attendanceDate) = $month
AND YEAR(att.attendanceDate) = $year
GROUP BY f.facultyInitial
ORDER BY f.facultyInitial";
$query = mysql_query($sql);
$row = mysql_num_rows($query);
if($row <> 0){
while($result = mysql_fetch_array($query)){
$data[] = $result['total'];
$leg[] = $result['facultyInitial'];
}

$graph = new Graph(500,400,"auto");

$graph->SetScale("textint");
$graph->img->SetMargin(50,30,50,50);
$graph->AdjBackgroundImage(0.4,0.7,-1);
$graph->SetShadow();

$graph->xaxis->SetTickLabels($leg);//

$bplot = new BarPlot($data);//
$bplot->SetFillColor("lightgreen"); // Fill color
$bplot->value->Show();
$bplot->value->SetFont(FF_ARIAL,FS_BOLD);
$bplot->value->SetAngle(45);
$bplot->value->SetColor("black","navy");

$graph->Add($bplot);
$graph->title->Set("Numbers of Students");
$graph->xaxis->title->Set("Faculty");
$graph->yaxis->title->Set("No. of Students");
$graph->Stroke();
}
else{
echo "<center><font face=\"Georgia, Times New Roman, Times, serif\" color=\"#000000\">Sorry, no record is found.</font></center>";
}
}

function splitDate($dateId){
$tempDate = explode('-', $dateId);

/*
* add 0 in front of the month if
* month parameter is between 1 and 9
*/
if($tempDate[1] >= 1 && $tempDate[1] <= 9)
$tempDate[1] = "0" . $tempDate[1];
else
$tempDate[1] = $tempDate[1];

generateGraph($tempDate[0], $tempDate[1]);
}

if(isset($dateId)){
splitDate($dateId);
}
}
else{
echo "<br><br><center><font face=\"Georgia, Times New Roman, Times, serif\">Warning: You are trying accessing restricted page.</font></center>";
header("Refresh:2, url='../auth/login_form.html'");
}
?>
[/code]
Link to comment
Share on other sites

This is your problem:
[code]echo "<br><br><center><font face=\"Georgia, Times New Roman, Times, serif\">Warning: You are trying accessing restricted page.</font></center>";
header("Refresh:2, url='../auth/login_form.html'");[/code]

You cant have anything outputted before calling the header function.
You may do:
[code]header("Refresh:5, url='../auth/login_form.html'");
echo "<br><br><center><font face=\"Georgia, Times New Roman, Times, serif\">Warning: You are trying accessing restricted page.</font></center>";[/code]

Orio.
Link to comment
Share on other sites

nope...nothing change...but how come these codes work? i used this code when trying jpgraph which is taken from phpfreaks.

[code]
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
session_start();
if(isset($_SESSION['user'])) {
include('../config_default.php');
include('../jpgraph/src/jpgraph.php'); 
include('../jpgraph/src/jpgraph_bar.php');
$year = 2006;
$sql = "SELECT COUNT(*) total, f.facultyInitial
FROM attendance att
INNER JOIN academic a
ON att.academicNo = a.academicNo
INNER JOIN program p
ON a.programId = p.programId
INNER JOIN faculty f
ON p.facultyId = f.facultyId
WHERE YEAR(att.attendanceDate) = $year
GROUP BY (f.facultyId)
ORDER BY f.facultyInitial";
$query = mysql_query($sql);
$row = mysql_num_rows($query);
if($row <> 0){
while($result = mysql_fetch_array($query)){
$data[] = $result['total'];
$leg[] = $result['facultyInitial'];
}

$graph = new Graph(500,400,"auto");

$graph->SetScale("textint");
$graph->img->SetMargin(50,30,50,50);
$graph->AdjBackgroundImage(0.4,0.7,-1);
$graph->SetShadow();

$graph->xaxis->SetTickLabels($leg);//

$bplot = new BarPlot($data);//
$bplot->SetFillColor("lightgreen"); // Fill color
$bplot->value->Show();
$bplot->value->SetFont(FF_ARIAL,FS_BOLD);
$bplot->value->SetAngle(45);
$bplot->value->SetColor("black","navy");

$graph->Add($bplot);
$graph->title->Set("Numbers of Students");
$graph->xaxis->title->Set("Faculty");
$graph->yaxis->title->Set("No. of Students");
$graph->Stroke();
}
else{
echo "Database is empty";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<br />
JpGraph 1
</body>
</html>
<?php
}
else{
echo "<br><br><center><font face=\"Georgia, Times New Roman, Times, serif\">Warning: You are trying accessing restricted page.</font></center>";
header("Refresh:2, url='../auth/login_form.html'");
}
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.