你可以试试KoolReport。
免责声明:我正在做这个项目。
它是一个 php 报告框架,正是您所寻找的。您可以通过网站下载框架,从github克隆项目或使用composer安装:composer require koolphp/koolreport
.
安装后,这里是创建销售报告的基本示例
index.php
: 这是引导文件
<?php
require_once "SalesByCustomer.php";
$salesByCustomer = new SalesByCustomer;
$salesByCustomer->run()->render();
SaleByCustomer.php
: 这个文件定义了数据连接和数据处理
<?php
require_once "koolreport/autoload.php";
use \koolreport\processes\Group;
use \koolreport\processes\Limit;
use \koolreport\processes\Sort;
class SalesByCustomer extends \koolreport\KoolReport
{
public function settings()
{
return array(
"dataSources"=>array(
"sales"=>array(
"connectionString"=>"mysql:host=localhost;dbname=db_sales",
"username"=>"root",
"password"=>"",
"charset"=>"utf8"
)
)
);
}
public function setup()
{
$this->src('sales')
->query("SELECT customerName,dollar_sales FROM customer_product_dollarsales")
->pipe(new Group(array(
"by"=>"customerName",
"sum"=>"dollar_sales"
)))
->pipe(new Sort(array(
"dollar_sales"=>"desc"
)))
->pipe(new Limit(array(10)))
->pipe($this->dataStore('sales_by_customer'));
}
}
SalesByCustomer.view.php
:这是您可以将数据可视化的视图文件
<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\BarChart;
?>
<div class="text-center">
<h1>Sales Report</h1>
<h4>This report shows top 10 sales by customer</h4>
</div>
<hr/>
<?php
BarChart::create(array(
"dataStore"=>$this->dataStore('sales_by_customer'),
"width"=>"100%",
"height"=>"500px",
"columns"=>array(
"customerName"=>array(
"label"=>"Customer"
),
"dollar_sales"=>array(
"type"=>"number",
"label"=>"Amount",
"prefix"=>"$",
)
),
"options"=>array(
"title"=>"Sales By Customer"
)
));
?>
<?php
Table::create(array(
"dataStore"=>$this->dataStore('sales_by_customer'),
"columns"=>array(
"customerName"=>array(
"label"=>"Customer"
),
"dollar_sales"=>array(
"type"=>"number",
"label"=>"Amount",
"prefix"=>"$",
)
),
"cssClass"=>array(
"table"=>"table table-hover table-bordered"
)
));
?>
这是结果。
基本上,您可以同时从多个数据源获取数据,将它们通过流程传输,然后将结果存储到数据存储中。然后数据存储中的数据将在视图中可用以进行可视化。Google Charts集成在框架内,因此您可以立即使用它来创建漂亮的图表和图形。
好的,这里有一些很好的链接:
- KoolReport 高级示例:查看更多优秀示例
- Doc - 数据源:支持 MySQL、Oracle、SQLServer、MongoDB、CSV、Microsoft Excel ..
- Doc - 数据处理:数据分析和转换
- Doc - 数据可视化:使用图表、表格等将您的数据可视化。
- Github 上的项目。
希望有帮助。