5.19. Example - Bar Chart with Data Value Labels

This is a bar chart with data value labels. Data value labels can be used as an alternative to (or along with) Y tick labels, but only with bar and stackedbar charts. (Bar chart data value labels were added to PHPlot-5.0rc3.)

Example 5.19. Bar Chart with Data Value Labels

Bar Chart with Data Value Labels Example
# PHPlot Example: Bar chart, with data labels
require_once 'phplot.php';

$data = array(
  array('China', 1306.31),           array('India', 1080.26),
  array('United States',  295.73),   array('Indonesia', 241.97),
  array('Brazil', 186.11),           array('Pakistan', 162.42),
  array('Bangladesh', 144.32),       array('Russia', 143.42),

$plot = new PHPlot(800, 600);
$plot->SetTitle("World's Most Populous Countries\n2005 Population in Millions");

# Turn off X tick labels and ticks because they don't apply here:

# Make sure Y=0 is displayed:
$plot->SetPlotAreaWorld(NULL, 0);
# Y Tick marks are off, but Y Tick Increment also controls the Y grid lines:

# Turn on Y data labels:

# With Y data labels, we don't need Y ticks or their labels, so turn them off.

# Format the Y Data Labels as numbers with 1 decimal place.
# Note that this automatically calls SetYLabelType('data').


SourceForge.net Logo

This version of the manual was produced for the PHPlot Sourceforge project web service site, which requires the logo on each page.

To download a logo-free copy of the manual, see the PHPlot project downloads area.