The above example shows you how to create LineChart
using D3 package. In this example, for purpose of chart demonstration only, we do use mock-up data from array. As you can see, the KoolReport's widget in general support dataSource could be DataStore, Process, DataSource or even simple array.
The example show how to create line chart with custom axis label.
For example:
...
"options" => array(
...
"axis" => array(
"y" => array(
"label" => 'Y Label'
),
"y2" => array(
"show" => true,
"label" => 'Y2 Label'
)
)
)
<?php
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
require_once "../../../../load.koolreport.php";
require_once "MyReport.php";
$report = new MyReport;
$report->run();
// $report->render();
?>
<?php
if (isset($_POST['command'])) {
?>
<div id="report_render">
<?php
$report->render();
?>
</div>
<?php
exit;
}
?>
<?php
if (!isset($_POST['command'])) {
?>
<div id="report_render">
<?php
$report->render();
?>
</div>
<?php
}
?>
<script>
setTimeout(function() {
$.ajax({
type: "POST",
url: 'run.php',
data: {
command: "second"
},
success: function(response) {
$('#report_render').html(response);
},
});
}, 1000)
setTimeout(function() {
$.ajax({
type: "POST",
url: 'run.php',
data: {
command: "third"
},
success: function(response) {
$('#report_render').html(response);
},
});
}, 2000)
</script>
<?php
class MyReport extends \koolreport\KoolReport
{
}
<h1 class='title'>Axis Label</h1>
<?php
$data = [
['data1' => 30, 'data2' => 50],
['data1' => 200, 'data2' => 20],
['data1' => 100, 'data2' => 10],
['data1' => 400, 'data2' => 40],
['data1' => 150, 'data2' => 15],
['data1' => 250, 'data2' => 25]
];
if (!isset($_POST['command'])) {
$_SESSION['yLabel'] = 'Y Axis Label';
$_SESSION['y2Label'] = 'Y2 Axis Label';
}
if (isset($_POST['command']) && $_POST['command'] === 'second') {
$_SESSION['yLabel'] = 'Y Axis Label';
$_SESSION['y2Label'] = 'New Y2 Axis Label';
}
if (isset($_POST['command']) && $_POST['command'] === 'third') {
$_SESSION['yLabel'] = 'New Y Axis Label';
$_SESSION['y2Label'] = 'New Y2 Axis Label Again';
}
\koolreport\d3\LineChart::create(array(
"dataSource" => $data,
"columns" => array(
'data1',
'data2',
),
"options" => array(
"data" => array(
"axes" => array(
"data1" => 'y',
"data2" => 'y2',
),
),
"axis" => array(
"y" => array(
"label" => $_SESSION['yLabel']
),
"y2" => array(
"show" => true,
"label" => $_SESSION['y2Label']
)
)
)
));