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 how to build a line chart with hide the label of every 2nd dataset, return null to hide the grid line too using the callback.
For example:
...
"xAxes" => array(
array(
"display" => true,
"ticks" => array(
"callback" => "function(dataLabel, index) {
return index % 2 === 0 ? dataLabel : '';
}"
)
)
),
<?php
require_once "../../../load.koolreport.php";
require_once "MyReport.php";
$report = new MyReport;
$report->run();
$report->render();
?>
<html>
<head>
<title>
Chart with xAxis Filtering
</title>
</head>
<body>
</body>
</html>
<?php
class MyReport extends \koolreport\KoolReport
{
}
<div id="report_render">
<?php
function randomScalingFactor()
{
return round(rand(0, 50) * (rand(0, 1) ? 1 : 1)) + 50;
}
$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(
"responsive" => true,
"title" => array(
"display" => true,
"text" => "Chart.js Line Chart - X-Axis Filter",
),
"scales" => array(
"xAxes" => array(
array(
"display" => true,
"ticks" => array(
"callback" => "function(dataLabel, index) {
// Hide the label of every 2nd dataset. return null to hide the grid line too
return index % 2 === 0 ? dataLabel : '';
}"
)
)
),
"yAxes" => array(
array(
"display" => true,
"beginAtZero" => false
)
)
)
)
));
?>
</div>
</div>