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();
}
?>
It seems you are trying to output the image through your php file itself. Do you have a line in your original script which reads like header('Content-Type:image/jpeg') ?
You might want to just write the image to a directory and then load it via img src='path' on html instead of just loading it via php.
Check to make sure the files are both in the same location. If they are in different directories, that can cause a problem if your included file isn't picking up the library from an include path.
精彩评论