Image_Graph, Bar plots and Legends
| From: | Markus Wolff | Date: | Mon, 21 Nov 2005 17:25:49 +0000 |
| Subject: | Image_Graph, Bar plots and Legends | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-22033@lists.php.net to get a copy of this message | ||
Hi there,
I'm making my first attempts with Image_Graph and I'm trying to accomplish something along the lines of this example:
http://pear.veggerby.dk/samples/index.php?sample=plot_bar_multiple
So I want to have a bar plot with multiple datasets for each point on the x-axis. Everything works fine for me using the latest released version of Image_Graph, except that all the entries in the legend say "Bar". Obviously, that's not what I want.
Just defining $Legend->setPlotarea($Plotarea) does not help as the names of the legend entries are not contained in the dataset, I'd have to have named datasets for that. A little bit of digging lead me to this example for a line plot:
$Plotarea->addNew('line', array($Dataset, 'normal', $legend));
This works, I get a line plot with three lines and the associated legend entries. However, when I change the plot type to "bar"...
$Plot =& $Plotarea->addNew('bar', array($Dataset, 'normal', $legend));
...I'm suddenly getting a stacked bar plot instead of having all the bars side-by-side in a row. And the plot values are kind of bogus as well.
Here's the complete loop that actually works, but without the legend names:
foreach($stats['axes']['y'] as $legend => $ypoints) {
$Dataset =& Image_Graph::factory('dataset');
for ($i=0; $i < count($ypoints); $i++) {
$Dataset->addPoint($stats['axes']['x'][$i], $ypoints[$i]);
}
$Datasets[] = $Dataset;
$Plot =& $Plotarea->addNew('bar', array($Dataset)); // name missing
}
I have a complete example up here:
http://www.21st.de/igraph.phps
Search for "PROBLEM AREA", which marks the spot.
Any help is appreciated.
CU
Markus