Axis Range

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 range.

For example:

...
"options" => array(
    ...
    "axis" => array(
        "x" => array(
            "max" =>5,
            "min" =>0
        ),
        "y" => array(
            "max" => '',
            "min" => ''
        ),
        "y2" => array(
            "show" => true,
            "max" => '',
            "min" => ''
        ),
    )
)
<?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)

    setTimeout(function() {
        $.ajax({
            type: "POST",
            url: 'run.php',
            data: {
                command: "fourth"
            },
            success: function(response) {
                $('#report_render').html(response);
            },
        });
    }, 3000)

    setTimeout(function() {
        $.ajax({
            type: "POST",
            url: 'run.php',
            data: {
                command: "fifth"
            },
            success: function(response) {
                $('#report_render').html(response);
            },
        });
    }, 4000)

    setTimeout(function() {
        $.ajax({
            type: "POST",
            url: 'run.php',
            data: {
                command: "sixth"
            },
            success: function(response) {
                $('#report_render').html(response);
            },
        });
    }, 5000)

    setTimeout(function() {
        $.ajax({
            type: "POST",
            url: 'run.php',
            data: {
                command: "seventh"
            },
            success: function(response) {
                $('#report_render').html(response);
            },
        });
    }, 6000)

    setTimeout(function() {
        $.ajax({
            type: "POST",
            url: 'run.php',
            data: {
                command: "eighth"
            },
            success: function(response) {
                $('#report_render').html(response);
            },
        });
    }, 7000)

    setTimeout(function() {
        $.ajax({
            type: "POST",
            url: 'run.php',
            data: {
                command: "ninth"
            },
            success: function(response) {
                $('#report_render').html(response);
            },
        });
    }, 8000)

    setTimeout(function() {
        $.ajax({
            type: "POST",
            url: 'run.php',
            data: {
                command: "tenth"
            },
            success: function(response) {
                $('#report_render').html(response);
            },
        });
    }, 9000)
</script>
<?php

class MyReport extends \koolreport\KoolReport
{

}
<h1 class='title'>Axis Range</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['yAxisMax'] = "";
    $_SESSION['yAxisMin'] = "";
    $_SESSION['y2AxisMax'] = "";
    $_SESSION['y2AxisMin'] = "";
    $_SESSION['xAxisMax'] = 5;
    $_SESSION['xAxisMin'] = 0;
}

if (isset($_POST['command']) && $_POST['command'] === 'second') {
    $_SESSION['yAxisMax'] = 500;
    $_SESSION['yAxisMin'] = "";
    $_SESSION['y2AxisMax'] = 500;
    $_SESSION['y2AxisMin'] = "";
    $_SESSION['xAxisMax'] = 5;
    $_SESSION['xAxisMin'] = 0;
}

if (isset($_POST['command']) && $_POST['command'] === 'third') {
    $_SESSION['yAxisMax'] = 500;
    $_SESSION['yAxisMin'] = -500;
    $_SESSION['y2AxisMax'] = 500;
    $_SESSION['y2AxisMin'] = -500;
    $_SESSION['xAxisMax'] = 5;
    $_SESSION['xAxisMin'] = 0;
}

if (isset($_POST['command']) && $_POST['command'] === 'fourth') {
    $_SESSION['yAxisMax'] = 600;
    $_SESSION['yAxisMin'] = -500;
    $_SESSION['y2AxisMax'] = 100;
    $_SESSION['y2AxisMin'] = -500;
    $_SESSION['xAxisMax'] = 5;
    $_SESSION['xAxisMin'] = 0;
}

if (isset($_POST['command']) && $_POST['command'] === 'fifth') {
    $_SESSION['yAxisMax'] = 600;
    $_SESSION['yAxisMin'] = -600;
    $_SESSION['y2AxisMax'] = 100;
    $_SESSION['y2AxisMin'] = -100;
    $_SESSION['xAxisMax'] = 5;
    $_SESSION['xAxisMin'] = 0;
}

if (isset($_POST['command']) && $_POST['command'] === 'sixth') {
    $_SESSION['yAxisMax'] = 1000;
    $_SESSION['yAxisMin'] = -1000;
    $_SESSION['y2AxisMax'] = 1000;
    $_SESSION['y2AxisMin'] = -1000;
    $_SESSION['xAxisMax'] = 5;
    $_SESSION['xAxisMin'] = 0;
}

if (isset($_POST['command']) && $_POST['command'] === 'seventh') {
    $_SESSION['yAxisMax'] = 600;
    $_SESSION['yAxisMin'] = -100;
    $_SESSION['y2AxisMax'] = 100;
    $_SESSION['y2AxisMin'] = 0;
    $_SESSION['xAxisMax'] = 5;
    $_SESSION['xAxisMin'] = 0;
}

if (isset($_POST['command']) && $_POST['command'] === 'eighth') {
    $_SESSION['yAxisMax'] = 600;
    $_SESSION['yAxisMin'] = -100;
    $_SESSION['y2AxisMax'] = 100;
    $_SESSION['y2AxisMin'] = 0;
    $_SESSION['xAxisMax'] = 10;
    $_SESSION['xAxisMin'] = '';
}

if (isset($_POST['command']) && $_POST['command'] === 'ninth') {
    $_SESSION['yAxisMax'] = 600;
    $_SESSION['yAxisMin'] = -100;
    $_SESSION['y2AxisMax'] = 100;
    $_SESSION['y2AxisMin'] = 0;
    $_SESSION['xAxisMax'] = 10;
    $_SESSION['xAxisMin'] = -10;
}

if (isset($_POST['command']) && $_POST['command'] === 'tenth') {
    $_SESSION['yAxisMax'] = 600;
    $_SESSION['yAxisMin'] = -100;
    $_SESSION['y2AxisMax'] = 100;
    $_SESSION['y2AxisMin'] = 0;
    $_SESSION['xAxisMax'] = 5;
    $_SESSION['xAxisMin'] = 0;
}

\koolreport\d3\LineChart::create(array(
    "dataSource" => $data,
    "columns" => array(
        'data1',
        'data2',
    ),
    "options" => array(
        "data" => array(
            "axes" => array(
                "data1" => 'y',
                "data2" => 'y2',
            ),
        ),
        "axis" => array(
            "x" => array(
                "max" => $_SESSION['xAxisMax'],
                "min" => $_SESSION['xAxisMin']
            ),
            "y" => array(
                "max" => $_SESSION['yAxisMax'],
                "min" => $_SESSION['yAxisMin']
            ),
            "y2" => array(
                "show" => true,
                "max" => $_SESSION['y2AxisMax'],
                "min" => $_SESSION['y2AxisMin']
            ),
        )
    )
));

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