Scatter Chart Multi Axis

The above example shows you how to create ScatterChart 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 how to build a multi-axis chart by using yAxisID and xAxisID properties and specifying the yAxisID and xAxisID for each series.

For example:

...
"series" => array(
        array(
            "FirstX", "FirstY",
            array(
                ...
                "xAxisID" => "x-axis-1",
                "yAxisID" => "y-axis-1"
            )
        ),
        array(
            "SecondX", "SecondY",
            array(
                ...
                "xAxisID" => "x-axis-1",
                "yAxisID" => "y-axis-2"
            )
        ),
    ),
    "options" => array(
        ...
        "scales" => array(
            "xAxes" => array(
                array(
                    ...
                    "id" => 'x-axis-1',
                )
            ),
            "yAxes" => array(
                array(
                    ...
                    "id" => 'y-axis-1'
                ),
                array(
                    ...
                    "id" => 'y-axis-2',
                )
            )
        )
    )
    ...
<?php
require_once "../../../load.koolreport.php";
require_once "MyReport.php";
$report = new MyReport;
$report->run();
?>
<?php
if (isset($_POST['command']) && $_POST['command'] === 'randomizeData') {
?>
    <div id='report_render'>
        <?php
        $report->render();
        ?>
    </div>
<?php
    exit;
}
?>

<?php
if (isset($_GET)) {
?>
    <div id='report_render'>
        <?php
        $report->render();
        ?>
    </div>
<?php
}
?>


<html>

<head>
    <title>
        Scatter Chart Multi Axis
    </title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
</head>

<body>
    <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>
    <div>
        <div id='report_render'>
        </div>
    </div>
</body>

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

    $datas = [
        ["FirstX" => randomScalingFactor(), "FirstY" => randomScalingFactor(), "SecondX" => randomScalingFactor(), "SecondY" => randomScalingFactor()],
        ["FirstX" => randomScalingFactor(), "FirstY" => randomScalingFactor(), "SecondX" => randomScalingFactor(), "SecondY" => randomScalingFactor()],
        ["FirstX" => randomScalingFactor(), "FirstY" => randomScalingFactor(), "SecondX" => randomScalingFactor(), "SecondY" => randomScalingFactor()],
        ["FirstX" => randomScalingFactor(), "FirstY" => randomScalingFactor(), "SecondX" => randomScalingFactor(), "SecondY" => randomScalingFactor()],
        ["FirstX" => randomScalingFactor(), "FirstY" => randomScalingFactor(), "SecondX" => randomScalingFactor(), "SecondY" => randomScalingFactor()],
        ["FirstX" => randomScalingFactor(), "FirstY" => randomScalingFactor(), "SecondX" => randomScalingFactor(), "SecondY" => randomScalingFactor()],
        ["FirstX" => randomScalingFactor(), "FirstY" => randomScalingFactor(), "SecondX" => randomScalingFactor(), "SecondY" => randomScalingFactor()],
    ];

    \koolreport\chartjs\ScatterChart::create(array(
        'dataSource' => $datas,
        "series" => array(
            array(
                "FirstX", "FirstY",
                array(
                    "label" => "My First dataset",
                    "backgroundColor" => 'rgba(255, 99, 132, 0.5)',
                    "borderColor" => 'rgb(255, 99, 132)',
                    "xAxisID" => "x-axis-1",
                    "yAxisID" => "y-axis-1"
                )
            ),
            array(
                "SecondX", "SecondY",
                array(
                    "label" => "My Second dataset",
                    "backgroundColor" => 'rgba(54, 162, 235, 0.5)',
                    "borderColor" => 'rgb(54, 162, 235)',
                    "xAxisID" => "x-axis-1",
                    "yAxisID" => "y-axis-2"
                )
            ),
        ),
        "options" => array(
            "responsive" => true,
            "hoverMode" => 'nearest',
            "intersect" => true,
            "title" => array(
                "display" => true,
                "text" => 'Chart.js Scatter Chart - Multi Axis'
            ),
            "scales" => array(
                "xAxes" => array(
                    array(
                        "position" => 'bottom',
                        "id" => 'x-axis-1',
                        "gridLines" => array(
                            "zeroLineColor" => 'rgb(0,0,0,1)'
                        )
                    )
                ),
                "yAxes" => array(
                    array(
                        "display" => true,
                        "position" => 'left',
                        "id" => 'y-axis-1'
                    ),
                    array(
                        "display" => true,
                        "position" => 'right',
                        "id" => 'y-axis-2',
                        "reverse" => true,
                        "gridLines" => array(
                            "drawOnChartArea" => false
                        )
                    )
                )
            )
        )
    ));
    ?>
</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