5.20. Example - Stacked Bars with Y Data Labels
Prev | Chapter 5. PHPlot Examples | Next

## 5.20. Example - Stacked Bars with Y Data Labels

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

Example 5.20. Stacked Bars with Y Data Labels

    <?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'));

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

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

    $plot->DrawGraph();

Prev | Up | Next
5.19. Example - Bar Chart with Data Labels | Home | 5.21. Example - Stacked Area Plot