<?php // content="text/plain; charset=utf-8"
// $Id: bar_csimex3.php,v 1.3 2002/08/31 20:03:46 aditus Exp $
// Horiontal bar graph with image maps
define('TTF_DIR',dirname(__FILE__).'/font/');
include ("C:/AppServ/www/JpGraph/src/jpgraph.php");
include ("C:/AppServ/www/JpGraph/src/jpgraph_bar.php");
include "config.php";
require("../cart/connect/function.php");
$resultDetail=select("nutritionfact","where ProductID='".$_GET["ProductID"]."'");
$a = $resultDetail["Ener"];
$b = $resultDetail["Suga"];
$c = $resultDetail["Total_F"];
$d = $resultDetail["Sodi"];
$data1y=array($a,$b,$c,$d);
$data2y=array(100-$a,100-$b,100-$c,100-$d);
// Setup the basic parameters for the graph
$graph = new Graph(500,700);
$graph->SetAngle(90);
$graph->SetScale("textlin");
// The negative margins are necessary since we
// have rotated the image 90 degress and shifted the
// meaning of width, and height. This means that the
// left and right margins now becomes top and bottom
// calculated with the image width and not the height.
$graph->img->SetMargin(-50,-50,210,210);
$graph->SetMarginColor('white');
// Setup title for graph
$graph->title->Set('Nutrition bar graph');
$graph->title->SetFont(FF_ANGSA,FS_BOLD,30);
$labels = array("พลังงาน", "น้ำตาล", "ไขมันทั้งหมด", "โซเดียม");
for ($i = 0; $i < count($labels); $i++) {
$labels[$i] = iconv ("tis-620","utf-8",$labels[$i]); }
$graph->xaxis->SetTickLabels($labels);
$graph->xaxis->SetFont (FF_ANGSA,FS_BOLD,18);
$graph->xaxis->SetLabelAngle(45);
// Setup Y-axis
// First we want it at the bottom, i.e. the 'max' value of the
// x-axis
$graph->yaxis->SetPos('max');
// Arrange the title
$title = iconv('TIS-620','UTF-8','ร้อยละของปริมาณที่แนะนำต่อวัน');
$graph->yaxis->title->SetFont(FF_ANGSA,FS_BOLD,18);
$graph->yaxis->title->SetAngle(0);
$graph->yaxis->SetTitle("$title",'center');
$graph->yaxis->SetTitleSide(SIDE_RIGHT);
$graph->yaxis->title->Align('center','top');
$graph->yaxis->SetTitleMargin(30);
// Arrange the labels
$graph->yaxis->SetLabelSide(SIDE_RIGHT);
$graph->yaxis->SetLabelAlign('center','top');
// Create the bar plots with image maps
$b1plot = new BarPlot($data1y);
$b1plot->SetFillColor("orange");
$targ=array("bar_clsmex2.php#1","bar_clsmex2.php#2","bar_clsmex2.php#3",
"bar_clsmex2.php#4");
$alts=array("val=%d","val=%d","val=%d","val=%d");
$b1plot->SetCSIMTargets($targ,$alts);
$b2plot = new BarPlot($data2y);
$b2plot->SetFillColor("blue");
$targ=array("bar_clsmex2.php#5","bar_clsmex2.php#6","bar_clsmex2.php#7",
"bar_clsmex2.php#8");
$alts=array("val=%d","val=%d","val=%d","val=%d");
$b2plot->SetCSIMTargets($targ,$alts);
// Create the accumulated bar plot
$abplot = new AccBarPlot(array($b1plot,$b2plot));
$abplot->SetShadow();
// We want to display the value of each bar at the top
$abplot->value->Show();
$abplot->value->SetFont(FF_FONT1,FS_NORMAL);
$abplot->value->SetAlign('left','center');
$abplot->value->SetColor("black","darkred");
$val = array("bar_clsmex2.php#1","bar_clsmex2.php#2","bar_clsmex2.php#3","bar_clsmex2.php#4");
$typ = array("%.2f","%.2f",".2f",".2f");
$abplot->value->SetFormat($val,$typ);
// ...and add it to the graph
$graph->Add($abplot);
// Send back the HTML page which will call this script again
// to retrieve the image.
$graph->StrokeCSIM();
?>
<?php
// ... necessary includes ...
$graph = new Graph(400,300);
// ... code to generate a graph ...
// Get the handler to prevent the library from sending the
// image to the browser
$gdImgHandler = $graph->Stroke(_IMG_HANDLER);
// Stroke image to a file and browser
// Default is PNG so use ".png" as suffix
$fileName = "/tmp/imagefile.png";
$graph->img->Stream($fileName);
// Send it back to browser
$graph->img->Headers();
$graph->img->Stream();
?>