Creating ImageMaps with PHP Image_Graph
Here’s the result:

The code is pretty long winded. I suggest you start by copying the entire code into your page and then progressively modifying it to suit your needs. Trust me, it’s better than developing from scratch. I’ve also wrapped it all into a single function call, so you could do this:
$graph =& bargraph($datas);
$graph->done(array('name'=>'fruits'));
Here’s the code in it’s entirety
$canvasType,
"width" => $width,
"height" => $height)));
$graph->setBackground($vgradient);
$title = Image_Graph::factory('title', array(' Monthly Fruit Production', 14));
$title->setAlignment(IMAGE_GRAPH_ALIGN_LEFT);
$title->setBackground($hgradient);
$arial =& $graph->addNew('ttf_font', '/nfsn/content/precis/htdocs/verdana.ttf');
$arial->setColor('#ffffff');
$graph->setFont($arial);
$arial->setSize(8);
$graph->add(
Image_Graph::vertical(
$title,
Image_Graph::vertical(
$plotarea = Image_Graph::factory('plotarea'),
$legend = Image_Graph::factory('legend'),
90),
15));
foreach ($datasets as $name => $dataset)
{
$data =& Image_Graph::factory('dataset');
$data->setName($name);
foreach ($dataset as $x => $y)
{
$data->addPoint($x,$y, array("url"=>"http://www.yahoo.com"));
}
$datas[] = $data;
}
$linestyle =& new Image_Graph_Line_Solid("#ffffff");
$linestyle->setThickness(2);
$fillstyle=Image_Graph::factory('Image_Graph_Fill_Array');
$fillstyle->add(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, '#ff8205', '#ffe016')));
$fillstyle->add(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, '#009100', '#00df00')));
$fillstyle->add(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, '#860000', '#fc0000')));
$legend->setPlotArea($plotarea);
$plot =& $plotarea->addNew('bar', array($datas));
$plot->setLineStyle($linestyle);
$plot->setFillStyle($fillstyle);
$plotarea->setPadding(20);
return $graph;
}
/* =================================
Example
*/
$datas = array(
"oranges" =>
array(
"Jan" => 17,
"Feb" => 18,
"Mar" => 19,
"Apr" => 10,
"May" => 12,
),
"pears" =>
array(
"Jan" => 11,
"Feb" => 13,
"Mar" => 15,
"Apr" => 18,
"May" => 22,
),
"apples" =>
array(
"Jan" => 15,
"Feb" => 16,
"Mar" => 17,
"Apr" => 18,
"May" => 18,
),
);
$graph =& bargraph($datas);
$graph->done(array('name'=>'fruits'));
?>
2 Comments
Jump to comment form | comments rss [?] | trackback uri [?]