5.20. Example - Stacked Bars with Y Data Value Labels

This is the same as Example 5.15, “Stacked Bars, Unshaded” except that Y data value labels are turned on. Note this feature was added in PHPlot-5.1.1.

Example 5.20. Stacked Bars with Y Data Value Labels

Stacked Bars with Y Data Value Labels Example
<?php
# PHPlot Example: Stacked Bars, unshaded, with Y data labels
require_once 'phplot.php';

$data = array(
  array('Jan', 40, 5, 10, 3), array('Feb', 90, 8, 15, 4),
  array('Mar', 50, 6, 10, 4), array('Apr', 40, 3, 20, 4),
  array('May', 75, 2, 10, 5), array('Jun', 45, 6, 15, 5),
  array('Jul', 40, 5, 20, 6), array('Aug', 35, 6, 12, 6),
  array('Sep', 50, 5, 10, 7), array('Oct', 45, 6, 15, 8),
  array('Nov', 35, 6, 20, 9), array('Dec', 40, 7, 12, 9),
);

$plot = new PHPlot(800, 600);
$plot->SetImageBorderType('plain');

$plot->SetPlotType('stackedbars');
$plot->SetDataType('text-data');
$plot->SetDataValues($data);

$plot->SetTitle('Candy Sales by Month and Product');
$plot->SetYTitle('Millions of Units');

# No shading:
$plot->SetShading(0);

$plot->SetLegend(array('Chocolates', 'Mints', 'Hard Candy', 'Sugar-Free'));
# Make legend lines go bottom to top, like the bar segments (PHPlot > 5.4.0)
$plot->SetLegendReverse(True);

$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');

# Turn on Y Data Labels: Both total and segment labels:
$plot->SetYDataLabelPos('plotstack');

$plot->DrawGraph();

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.