Data from URL

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.

This example shows how to build a basic line chart with data from URL.

<?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);

</script>
<?php
require_once "../../../../load.koolreport.php";
class MyReport extends \koolreport\KoolReport
{
    function settings()
    {
        return array(
            "dataSources" => array(
                "data1" => array(
                    'filePath' => '../../../../databases/c3_test.csv',
                    'fieldSeparator' => ';',
                    'class' => "\koolreport\datasources\CSVDataSource"
                ),
            )
        );
    }
    function setup()
    {
        $this->src("data1")->pipe($this->dataStore('firstData'));
        $jsonData = file_get_contents('../../../../databases/c3_test.json');
        $arrayData = json_decode($jsonData, true);
        $transformedData = [];
        $rowCount = count($arrayData["data1"]);
        for ($i = 0; $i < $rowCount; $i++) {
            $transformedData[] = array(
                "data1" => $arrayData["data1"][$i],
                "data2" => $arrayData["data2"][$i],
                "data3" => $arrayData["data3"][$i],
            );
        }
        $this->dataStore("secondData")->data($transformedData);
    }
}
<div id="report_render">
    <h1 class="title">Data from URL</h1>
    <?php
    if (!isset($_POST['command'])) {
        $_SESSION['data'] = $this->dataStore('firstData')->toArray();
        for ($i = 0; $i < count($_SESSION['data']); $i++) {
            $_SESSION['data'][$i]['data1'] = intval($_SESSION['data'][$i]['data1']);
        }
    }

    if (isset($_POST['command']) && $_POST['command'] === 'second') {
        $_SESSION['data'] = $this->dataStore('secondData')->toArray();
    }


    \koolreport\d3\LineChart::create(array(
        "dataSource" => $_SESSION['data'],
        "columns" => array(
            'data1',
            'data2',
            'data3'
        ),
    ));
    ?>
</div>

What People Are Saying

"KoolReport helps me very much in creating data report for my corporate! Keep up your good work!"
-- Alain Melsens

"The first use of your product. I was impressed by its easiness and powerfulness. This product is a great and amazing."
-- Dr. Lew Choy Onn

"Fantastic framework for reporting!"
-- Greg Schneider

Download KoolReport Get KoolReport Pro