Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.8.0

Bug #11897 Wrong color assignment in multi-dataset plots
Submitted: 2007-08-23 13:41 UTC
From: sandermarechal Assigned: nosey
Status: Assigned Package: Image_Graph (version 0.7.2)
PHP Version: 5.2.0 OS: Linux (Debian Etch)
Roadmaps: (Not assigned)    
Subscription  


 [2007-08-23 13:41 UTC] sandermarechal (Sander Marechal)
Description: ------------ For my graphs I have created a default set of colors to use simply by creating an Image_Graph_Fill_Array that everything uses. The amount of datasets in my plots usually changes (depending on the data) so I have created a standard bar graph that acts as a plot with multiple datasets. However, when only one dataset is actually present, every bar gets a different color instead of all the bars being the same color. It starts picking one color per datapoint instead of one color per dataset. I think that it should always use one color per dataset if I create a plot with multiple datasets (e.g. 'stacked'), even though there is only one dataset it it. Test script: --------------- #!/usr/bin/php -q <?php require_once('Image/Graph.php'); $graph =& Image_Graph::factory('graph', array(array('width' => 400, 'height' => 300, 'canvas' => 'svg'))); $graph->setBackgroundColor('white'); $graph->add($plotarea = Image_Graph::factory('plotarea')); $color_array =& Image_Graph::factory('Image_Graph_Fill_Array'); $color_array->addColor('red'); $color_array->addColor('green'); $color_array->addColor('blue'); $dataset =& Image_Graph::factory('dataset'); $dataset->addPoint(0, 8); $dataset->addPoint(1, 7); $dataset->addPoint(2, 9); // A 'multiple dataset' graph, but with one actual dataset. This makes all three bars a different color. // If I would do instead: addNew('bar', array(array($dataset, $dataset), 'stacked')); // then I would get a good plot with one color per dataset $plot =& $plotarea->addNew('bar', array(array($dataset), 'stacked')); $plot->setFillStyle($color_array); $graph->done(array('filename' => 'test.svg')); ?> Expected result: ---------------- One color per dataset -- even if there just happens to be only one dataset in the array of datasets. Actual result: -------------- Each bar of the dataset gets a different color.

Comments

 [2007-08-23 15:02 UTC] nosey (Jesper Veggerby)
This is actually working as designed. Consider the case where you actually WANT a bar chart to have different colors for each bar... If you look at the code, you can see that this is coded explicitly: Image_Graph_Plot_Bar: $ID = $point['ID']; if (($ID === false) && (count($this->_dataset) > 1)) { $ID = $key; } $this->_getFillStyle($ID); $this->_getLineStyle($ID);
 [2007-08-23 16:13 UTC] sandermarechal (Sander Marechal)
Well, if I WANT a bar chart to have different colored bars, I would do: $plot =& $plotarea->addNew('bar', array($dataset)); instead of: $plot =& $plotarea->addNew('bar', array(array($dataset))); I think Image_Graph should distinguish between: one color per bar: array($dataset) one color per dataset: array(array($dataset)) Kind regards, -- Sander Marechal PS: Apologies if I shouldn't have re-opened it just because of my comment/explanation.