您可以尝试酷报告.
免责声明:我正在研究这个项目。
它是一个 PHP 报告框架,正是您所寻找的。您可以通过网站下载框架,clone来自 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"
)
));
?>
这是结果.
基本上,您可以同时从许多数据源获取数据,通过流程传输它们,然后将结果存储到数据存储中。然后,数据存储中的数据将在视图中可用以实现可视化。这谷歌图表集成在框架内,因此您可以立即使用来创建漂亮的图表和图形。
好吧,这里有一些很好的链接:
-
KoolReport 高级示例: 看更多好的例子
-
文档 - 数据源:支持 MySQL、Oracle、SQLServer、MongoDB、CSV、Microsoft Excel ..
-
文档-数据处理:数据分析与转换
-
文档-数据可视化:使用图表、表格等来可视化您的数据。
-
Github 上的项目.
希望有帮助。