Pure PHP
Overview #
What we means by pure PHP is that you don't use any kind of framework, you only need to draw charts inside a single php file.
Usage #
Load library #
First things first, you will need to load KoolRepport's library. If you install KoolReport manually with downloading and copying koolreport
folder into your app, you will need to require the library before you can use:
<?php
require_once "/path/to/koolreport/core/autoload.php";
Use any widgets #
Now you can use any widget of KoolReport inside your php file:
index.php
<?php
require_once "/path/to/koolreport/core/autoload.php";
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\ColumnChart;
$data = array(
array("category"=>"Books","sale"=>32000,"cost"=>20000,"profit"=>12000),
array("category"=>"Accessories","sale"=>43000,"cost"=>36000,"profit"=>7000),
array("category"=>"Phones","sale"=>54000,"cost"=>39000,"profit"=>15000),
array("category"=>"Movies","sale"=>23000,"cost"=>18000,"profit"=>5000),
array("category"=>"Others","sale"=>12000,"cost"=>6000,"profit"=>6000)
);
?>
<html>
<head>
<title>KoolReport's Widgets</title>
</head>
<body>
<body>
<?php
Table::create(array(
"dataSource"=>$data
));
?>
<?php
ColumnChart::create(array(
"dataSource"=>$data
));
?>
</body>
</html>
So if you have data available, just feed them to KoolReport's widget to visualize like above.
With database #
There is convenient way to visualize your data from database. Here is an example:
<?php
require_once "/path/to/koolreport/core/autoload.php";
use \koolreport\datasources\PdoDataSource;
use \koolreport\widgets\google\ColumnChart;
$connection = array(
"connectionString"=>"mysql:host=localhost;dbname=sales",
"username"=>"root",
"password"=>"",
"charset"=>"utf8"
);
?>
<html>
<head>
<title>KoolReport's Widgets</title>
</head>
<body>
<body>
<?php
ColumnChart::create(array(
"dataSource"=>(new PdoDataSource($connection))->query("
SELECT customerName,sum(amount) as total
FROM orders
GROUP BY customerName
")
));
?>
</body>
</html>
Code explanation:
$connection
contains the settings to connect to your database- In this example we use
PdoDataSource
as medium to connect to your data. - As you can see in the
"dataSource"
ofColumnChart
, we create new instance ofPdoDataSource
with$connection
settings and then followed with the SQL query.
This is very convenient way to connect, query and visualize your data. KoolReport has done almost all hard work for you.
Get started with KoolReport
KoolReport will help you to construct good php data report by gathering your data from multiple sources, transforming them into valuable insights, and finally visualizing them in stunning charts and graphs.