Hey guys.
I'm using a class that I found online that works on other sites. Here is the class.
Example
Okay, so using that class, I follow his tutorial and I my code works fine. No problems. I debug it, and I get the values I want.
The problem is that it doesn't output a gif, but rather gives me an error that headers have already been sent, but I don't know where or why. Any help would be greatly appreciated.
<?php
@include_once($_SERVER['DOCUMENT_ROOT'].'/test_new_version/scripts/config.php');
@require($dir['inc'].'class.phpbargraph.php');
$img = "gif";
if(!class_exists("PhpBarGraph"))
{
die("There was an error loading the class.");
}
$imageHeight = 150;
$imageWidth = 150;
$image = imageCreateTrueColor($imageWidth, $imageHeight);
$backgroundColor = ImageColorAllocate($image, 248, 248, 248);
$orange = ImageColorAllocate($image, 255, 153, 0);
$ltblue = ImageColorAllocate($image, 0, 153, 204);
ImageFill($image, 0, 0, $backgroundColor);
Imageinterlace($image, 1);
$statGraph = new PhpBarGraph;
$statGraph->SetX(10);
$statGraph->SetY(10);
$statGraph->SetWidth($imageWidth-20);
$statGraph->SetHeight($imageHeight-20);
$statGraph->SetNumOfValueTicks(0);
$statGraph->SetShowLabels(TRUE);
// The default is true.
// Setting this to false will cause phpBarGraph to not print the labels of each bar.
$statGraph->SetShowValues(TRUE);
// The default is true.
// Setting this to false will cause phpBarGraph to not print the values of each bar.
$statGraph->SetBarBorder(TRUE);
// The default is true.
// Setting this to false will cause phpBarGraph to not print the border of each bar.
$statGraph->SetShowFade(TRUE);
// The default is true.
// Setting this to false will cause phpBarGraph to not print each bar as a gradient.
$statGraph->SetShowOuterBox(TRUE);
// The default is true.
// Setting this to false will cause phpBarGraph to not print the outside box.
$statGraph->SetBarSpacing(20);
// The default is 10.
// This changes the space inbetween each bar.
$sql = "SELECT * FROM `statistics_test` ORDER BY id ASC";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$statGraph->AddValue($row['Month'], $row['Number']);
}
$statGraph->SetStartBarColor("ffcc00");
$statGraph->SetEndBarColor("990000");
$statGraph->SetLineColor("000000");
$statGraph->DrawBarGraph($image);
// Uncomment to turn debug on.
// $statGraph->DebugPrint();
if($img == "png")
{
header("Content-type: image/png");
ImagePNG($image);
}
elseif($img == "gif")
{
header("Content-type: image/gif");
ImageGif($image);
}
Imagedestroy($image);
?>
~Brett