PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Images » Image_Graph » Bug #7423

No bar for datasets with single value

Details

Submitted2006-04-19 14:47 UTC
Fromchristoffer at natlikan dot se
StatusNo Feedback
PackageImage_Graph
PHP Version5.1.1
OSLinux 2.4.21
Roadmaps(Not assigned)

Comments

[2006-04-19 14:47 UTC] christoffer at natlikan dot se

Description:
------------
When you have datasets with only one value no bar will show upp. I know it's kind of silly to have a graph with only one bar... but it's not my call.

I've been trying to fix it and think I've come up with a solution. By changing the lines 705-707 in Axis.php

from:
if ($this->_axisValueSpan == 0) {
$this->_delta = false;
} elseif ($this->_type == IMAGE_GRAPH_AXIS_X) {

to:
/*
if ($this->_axisValueSpan == 0) {
$this->_delta = false;
} elseif ($this->_type == IMAGE_GRAPH_AXIS_X) { */
if ($this->_type == IMAGE_GRAPH_AXIS_X) {

In other words, by removing the first if-satement.

Test script:
---------------
<?php
require_once 'Image/Graph.php';

// Create the graph
$Graph =& Image_Graph::factory('graph', array(400, 300));
// Add a TrueType font
$Font =& $Graph->addNew('font', 'Verdana');
// Set the font size to 11 pixels
$Font->setSize(8);

$Graph->setFont($Font);

$Graph->add(
Image_Graph::vertical(
Image_Graph::factory('title', array('Bar Chart Sample', 12)),
Image_Graph::vertical(
$Plotarea = Image_Graph::factory('plotarea'),
$Legend = Image_Graph::factory('legend'),
90
),
5
)
);

$Legend->setPlotarea($Plotarea);

// Create the dataset
$Dataset =& Image_Graph::factory('random', array(1, 2, 15, false));
// Create the 1st plot as smoothed area chart using the 1st dataset
$Plot =& $Plotarea->addNew('bar', array(&$Dataset));

// Set a line color
$Plot->setLineColor('gray');

// Set a standard fill style
$Plot->setFillColor('blue@0.2');

// Output the Graph
$Graph->done();
?>

Expected result:
----------------
A graph with one centered bar.

Actual result:
--------------
A graph with no bar at all.

[2006-04-25 04:26 UTC] alex_lai at hotmail dot com

I want to provide my testing result for generating a graph with only one bar in it for v0.7.2.

If the x-axis is a Image_Graph_Axis_Category or Image_Graph_Axis, the bar does get plotted. However, the bar is plotted right on the y-axis. If you change the color of the bar graph you will be able to view this. For a logarithmic axis, the single bar is generated correctly.

There are existing work arounds for this behavior. If the x-axis is linear, Image_Graph_Axis, then force a minimum and maximum x-axis value and the bar will display nicely. If the x-axis is a category type, Image_Graph_Axis_Category, then add additional value to the dataset with x and y value (y's set to zero) in the desired order to have it appear on the x-axis.

A possible appropriate behavior is to modify the code to let users input an offset value from the y-axis for the first value on the x-axis or vice versa, something like, setAxisOffset. This would also be beneficial for logarithmic axis as well.

Alex