5.4. Example - Bar Chart
Prev | Chapter 5. PHPlot Examples | Next

## 5.4. Example - Bar Chart

This is a bar chart with three data sets plotted. The data type is 'text-data', so the X values are implicit. But the X values are not relevant because the data labels (month names) are used instead, and the X tick marks and labels are turned off. This plot uses the default shading of bars.

Example 5.4. Bar Chart

    <?php
    # PHPlot Example: Bar chart, 3 data sets, shaded
    require_once 'phplot.php';

    $data = array(
      array('Jan', 40, 2, 4), array('Feb', 30, 3, 4), array('Mar', 20, 4, 4),
      array('Apr', 10, 5, 4), array('May',  3, 6, 4), array('Jun',  7, 7, 4),
      array('Jul', 10, 8, 4), array('Aug', 15, 9, 4), array('Sep', 20, 5, 4),
      array('Oct', 18, 4, 4), array('Nov', 16, 7, 4), array('Dec', 14, 3, 4),
    );

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

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

    # Main plot title:
    $plot->SetTitle('Shaded Bar Chart with 3 Data Sets');

    # Make a legend for the 3 data sets plotted:
    $plot->SetLegend(array('Engineering', 'Manufacturing', 'Administration'));

    # Turn off X tick labels and ticks because they don't apply here:
    $plot->SetXTickLabelPos('none');
    $plot->SetXTickPos('none');

    $plot->DrawGraph();

Prev | Up | Next
5.3. Example - Area Plot | Home | 5.5. Example - Unshaded Bar Chart