Pareto Chart

This example shows how to create Pareto Chart

This example shows how we can make Pareto Chart.

The Pareto Chart has this definition: "A Pareto chart, named after Vilfredo Pareto, is a type of chart that contains both bars and a line graph, where individual values are represented in descending order by bars, and the cumulative total is represented by the line. ... The Pareto chart is one of the seven basic tools of quality control."

So in this example, we use CSVDataSource to read data from data.csv contaning category and sale column. We use the ComboChart to create chart with both bar and line type.

The data come from the source will be sorted with Sort process and then we create running_sale column with AccumulativeColumn process

$this->src('data')
->pipe(new Sort(array(
    "sale"=>"desc"
)))
->pipe(new AccumulativeColumn(array(
    "running_sale"=>"sale"
)))

Note: In this example, the data do not share among different widgets so we use src() and processes directly in the chart. This is also a feature of KoolReport's widget which can receive data directly from DataSource or Process.

In the _runningsale we use line as chartType. Also in the "options" we define 2 axes and matching them with series.

"options"=>array(
    "vAxes"=>array(
        array("label"=>"Sale"),
        array("label"=>"Running Sale"),  
    ),
    "series"=>array(
        0=>array("targetAxisIndex"=>0), //"amount series"
        1=>array("targetAxisIndex"=>1), //"running_total"
    )
)

Enjoy the example!

<?php

require_once "../../../load.koolreport.php";
require_once "MyReport.php";

$report = new MyReport;
$report->run()->render();
<?php

class MyReport extends \koolreport\KoolReport
{
    public function settings()
    {
        return array(
            "dataSources"=>array(
                "data"=>array(
                    "class"=>'\koolreport\datasources\CSVDataSource',
                    "filePath"=>dirname(__FILE__)."/data.csv",
                )
            )
        );
    }   
}
<?php
    use \koolreport\widgets\google\ComboChart;
    use \koolreport\processes\AccumulativeColumn;
    use \koolreport\processes\Sort;
?>
<div class="report-content">
    <div class="text-center">
        <h1>Pareto Chart</h1>
        <p class="lead">
            This example shows how to create Pareto Chart
        </p>
    </div>

    <div style="margin-bottom:50px;">
    <?php
    ComboChart::create(array(
        "title"=>"Sale Report",
        "dataSource"=>(
            $this->src('data')
            ->pipe(new Sort(array(
                "sale"=>"desc"
            )))
            ->pipe(new AccumulativeColumn(array(
                "running_sale"=>"sale"
            )))
        ),
        "columns"=>array(
            "category"=>array(
                "label"=>"Month",
                "type"=>"date",
                "format"=>"Y-m",
                "displayFormat"=>"F, Y"
            ),
            "sale"=>array(
                "label"=>"Sale",
                "type"=>"number",
                "prefix"=>"$",
            ),
            "running_sale"=>array(
                "label"=>"Total",
                "type"=>"number",
                "prefix"=>"$",
                "chartType"=>"line",
            ),
        ),
        "options"=>array(
            "vAxes"=>array(
                array("label"=>"Sale"),
                array("label"=>"Running Sale"),  
            ),
            "series"=>array(
                0=>array("targetAxisIndex"=>0), //"amount series"
                1=>array("targetAxisIndex"=>1), //"running_total"
            )
        )
    ));
    ?>
    </div>
</div>
categorysalecost
Books 32000 20000
Accessories 43000 36000
Phones 54000 39000
Movies 23000 18000
Others 12000 6000

What People Are Saying

"KoolReport helps me very much in creating data report for my corporate! Keep up your good work!"
-- Alain Melsens

"The first use of your product. I was impressed by its easiness and powerfulness. This product is a great and amazing."
-- Dr. Lew Choy Onn

"Fantastic framework for reporting!"
-- Greg Schneider

Download KoolReport Get KoolReport Pro