I'm trying to write a wrapper around Image_Graph bar charts. I actually wrote the whole thing but in the end didn't work, so now I'm back to the basics. This code below is taken directly from the ImageGraph website as a bar chart example. I just wrapped it in a function (where $data is ignored for now).
This function works fine if I call it from the same file it's defined in (say, function.php). However, if I make a second file, caller.php where I just include_once or require_once this file function.php and then just call the function, it breaks.
Can anyone help me? I'm probably doing some basic mistake but I just can't figure it out. It might also be something specific to Image_Graph because if I make a simple function that just prints Hello World and call that from another file, it works fine.
Thanks, Daniel
<?php
include_once('Image/Graph.php');
function DrawBarChart($width, $height, $data)
{
// create the graph
$graph = Image_Graph::factory('graph', array($width, $height));
// create the plotarea
$plotArea =& $graph->addNew('plotarea');
// create a dataset
$dataset =& Image_Graph::factory('dataset');
// add points
$dataset->addPoint('Denmark', 10);
$dataset->addPoint('Norway', 3);
$dataset->addPoint('Sweden', 8);
$dataset->addPoint('Finland', 5);
$plot =& $plotArea->addNew('bar', &$dataset);
$graph->done();
}
?>