Stacked Charts

Stacked Column Charts

You can create a stacked column chart by creating a regular column chart and passing an extra property seriesStacked:true in your series configuration. You also need to specify the seriesDisplayType.

    $chart->addSeries ("packaged_foods", "Packaged Foods", [1513, 976, 1321], array(
        'numberPrefix' => "$",
        'seriesStacked' => true,
        'seriesDisplayType' => "column"
    ));
    $chart->addSeries ("vegetables", "Vegetables", [1313, 1976, 924], array(
        'numberPrefix' => "$",
        'seriesStacked' => true,
        'seriesDisplayType' => "column"
    ));
You currently cannot mix stacked series columns with other types, like line, or make multiple stacks, although this functionality is going to be available soon

Adding number prefixes and suffixes

Since multiple stacked series share similar number formatting properties, you will have to set the number formatting properties using the setYAxis function.

    $chart->setYAxis ("Sales", array(
        'numberPrefix' => "$"
    ));

Complete example

<?php

class SampleDashboard extends StandaloneDashboard { public function buildDashboard(){ $chart = new ChartComponent("2011_sales"); $chart->setDimensions (4, 4); $chart->setCaption("Stacked Column Chart");
$chart->setYAxis ("", array( 'numberPrefix' => "$" )); $chart->setLabels (["Jan", "Feb", "Mar"]); $chart->addSeries ("beverages", "Beverages", [1355, 1916, 1150], array( 'numberPrefix' => "$", 'seriesStacked' => true, 'seriesDisplayType' => "column" ));

$chart->addSeries ("packaged_foods", "Packaged Foods", [1513, 976, 1321], array(
    'numberPrefix' => "$",
    'seriesStacked' => true,
    'seriesDisplayType' => "column"
));
$chart->addSeries ("vegetables", "Vegetables", [1313, 1976, 924], array(
    'numberPrefix' => "$",
    'seriesStacked' => true,
    'seriesDisplayType' => "column"
));
$this->addComponent ($chart);

} }

$db = new SampleDashboard(); $db->renderStandalone();