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 line charts with different line styles using the borderDash
and fill
properties.
For example:
...
'columns' => array(
'month',
'Unfilled' => array(
...
),
'Dashed' => array(
"borderDash" => [5, 5],
...
),
'Filled' => array(
"fill" => true,
...
)
)
...
<div id="report_render">
<?php
function randomScalingFactor()
{
return mt_rand(-100, 100);
}
$data = [
['month' => 'February', 'Unfilled' => randomScalingFactor(), 'Dashed' => randomScalingFactor(), 'Filled' => randomScalingFactor()],
['month' => 'January', 'Unfilled' => randomScalingFactor(), 'Dashed' => randomScalingFactor(), 'Filled' => randomScalingFactor()],
['month' => 'March', 'Unfilled' => randomScalingFactor(), 'Dashed' => randomScalingFactor(), 'Filled' => randomScalingFactor()],
['month' => 'April', 'Unfilled' => randomScalingFactor(), 'Dashed' => randomScalingFactor(), 'Filled' => randomScalingFactor()],
['month' => 'May', 'Unfilled' => randomScalingFactor(), 'Dashed' => randomScalingFactor(), 'Filled' => randomScalingFactor()],
['month' => 'June', 'Unfilled' => randomScalingFactor(), 'Dashed' => randomScalingFactor(), 'Filled' => randomScalingFactor()],
['month' => 'July', 'Unfilled' => randomScalingFactor(), 'Dashed' => randomScalingFactor(), 'Filled' => randomScalingFactor()],
];
\koolreport\chartjs\LineChart::create(
array(
'dataSource' => $data,
'columns' => array(
'month',
'Unfilled' => array(
"backgroundColor" => 'rgb(54, 162, 235)',
"borderColor" => 'rgb(54, 162, 235)',
),
'Dashed' => array(
"borderDash" => [5, 5],
"backgroundColor" => 'rgb(75, 192, 192)',
"borderColor" => 'rgb(75, 192, 192)',
),
'Filled' => array(
"fill" => true,
"backgroundColor" => 'rgb(255, 99, 132)',
"borderColor" => 'rgb(255, 99, 132)',
)
),
"options" => array(
"responsive" => true,
"title" => array(
"display" => true,
"text" => "Chart.js Line Chart"
),
"tooltips" => array(
"mode" => 'index',
"intersect" => false,
),
"hover" => array(
"mode" => 'nearest',
"intersect" => true,
),
"scales" => array(
"xAxes" => array(
array(
"display" => true,
"scaleLabel" => array(
"display" => true,
"labelString" => "Month",
)
)
),
"yAxes" => array(
array(
"display" => true,
"scaleLabel" => array(
"display" => true,
"labelString" => "Value"
)
)
)
)
)
)
);
?>
</div>