Animation Callbacks

The above example shows you how to create LineChart using ChartJs 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 you how to build a line chart with a progress bar during the chart animation using animation.

For example:

... 
"options" => array(
    ...
    "animation" => array(
        "duration" => 2000,
        "onProgress" => "function(animation) {
            progress.value = animation.currentStep / animation.numSteps;
        }",
        "onComplete" => "function() {
            window.setTimeout(function() {
                progress.value = 0;
            }, 2000);
        }"
    )
)
...
<?php
require_once "../../../load.koolreport.php";
require_once "MyReport.php";
$report = new MyReport;
$report->run();
?>
<?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
}
?>

<html>

<head>
    <title>
        Animation Callbacks
    </title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
</head>

<body>
    <div>
        <div id="report_render"></div>
    </div>
    <br />
    <button id="randomizeData" class="btn">Randomize Data</button>
    <script>
        $(document).ready(function() {
            $('#randomizeData').click(function(e) {
                e.preventDefault();
                $.ajax({
                    type: "POST",
                    url:'run.php',
                    data: {
                        command: "randomizeData"
                    },
                    success: function(response) {
                        $('#report_render').html(response);
                    }
                })
            })
        })
    </script>
</body>

</html>
<?php
class MyReport extends \koolreport\KoolReport
{
    use \koolreport\clients\jQuery;
}
<div id="report_render">
    <?php
    function randomScalingFactor()
    {
        return mt_rand(-100, 100);
    }

    $data = [
        ['month' => 'January',  'My First dataset' => randomScalingFactor(), 'My Second dataset' => randomScalingFactor()],
        ['month' => 'February', 'My First dataset' => randomScalingFactor(), 'My Second dataset' => randomScalingFactor()],
        ['month' => 'March',    'My First dataset' => randomScalingFactor(), 'My Second dataset' => randomScalingFactor()],
        ['month' => 'April',    'My First dataset' => randomScalingFactor(), 'My Second dataset' => randomScalingFactor()],
        ['month' => 'May',      'My First dataset' => randomScalingFactor(), 'My Second dataset' => randomScalingFactor()],
        ['month' => 'June',     'My First dataset' => randomScalingFactor(), 'My Second dataset' => randomScalingFactor()],
        ['month' => 'July',     'My First dataset' => randomScalingFactor(), 'My Second dataset' => randomScalingFactor()],
    ];

    \koolreport\chartjs\LineChart::create(array(
        'dataSource' => $data,
        'columns' => array(
            "month",
            "My First dataset" => array(
                "fill" => false,
                "backgroundColor" => 'rgb(255, 99, 132)',
                "borderColor" => 'rgb(255, 99, 132)'
            ),
            "My Second dataset" => array(
                "fill" => false,
                "backgroundColor" => 'rgb(54, 162, 235)',
                "borderColor" => 'rgb(54, 162, 235)'
            )
        ),
        "options" => array(
            "title" => array(
                "display" => true,
                "text" => 'Chart.js Line Chart - Animation Progress Bar'
            ),
            "animation" => array(
                "duration" => 2000,
                "onProgress" => "function(animation) {
                    progress.value = animation.currentStep / animation.numSteps;
                }",
                "onComplete" => "function() {
                    window.setTimeout(function() {
                        progress.value = 0;
                    }, 2000);
                }"
            )
        )
    ));
    ?>
    <progress id="animationProgress" max="1" value="0" style="width: 100%"></progress>
</div>
<script>
    var progress = document.getElementById('animationProgress');
</script>

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