你可以试试KoolReport。
免责声明:我正在从事这个项目。
它是一个 php 报告框架,正是您所寻找的。您可以通过网站下载框架,克隆project from 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"
)
));
?>
这里是the result。
基本上,您可以同时从多个数据源获取数据,将它们通过流程传输,然后将结果存储到数据存储中。然后数据存储中的数据将在视图中可用以进行可视化。 Google Charts 集成在框架内,因此您可以立即使用来创建漂亮的图表和图形。
好的,这里有一些不错的链接:
-
KoolReport Advanced Examples : 查看更多好例子
-
Doc - Data Sources:支持 MySQL、Oracle、SQLServer、MongoDB、CSV、Microsoft Excel ..
-
Doc - Data Processing:数据分析与转换
-
Doc - Data Visualization:通过图表、表格等方式将您的数据可视化。
-
Project on Github。
希望对您有所帮助。