AreaChart
Overview #
Code:
<?php
\koolreport\chartjs\AreaChart::create(array(
"title"=>"Sale vs Cost",
"dataSource"=>$this->dataStore('month_sales'),
"columns"=>array(
"month",
"sale"=>array("label"=>"Sale","type"=>"number","prefix"=>"$"),
"cost"=>array("label"=>"Cost","type"=>"number","prefix"=>"$"),
)
));
Above example show minimum settings to setup a area chart. We use 2 columns from datasource which are "category' and "amount" to draw chart.
Note that: we may add extra column and the extra column will represent another series on the chart. The first column is used for xAxis labeling.
Settings #
name | type | default | description |
---|---|---|---|
name | string | Set name for chart. It is optional | |
title | string | Title of the chart | |
dataSource | mixed | Set the data source for chart, accepting DataStore, DataSource, Process object and even array in table or associate format | |
columns | array | List of columns used to draw chart | |
options | array | Extra options for area chart, please view options section for more details | |
backgroundOpacity | number | 0.5 | Set the opacity for background |
axes | array | Defined multiple axes for your chart |
Properties of a column #
Except for the first column, the next column in the columns
list will represent a series of data on the chart. We may have further settings for each column. Below are properties we can set for column.
Example
<?php
AreaChart::create(array(
"dataSource"=>$this->dataStore("category_amount"),
"columns"=>array(
"category",
"amount"=>array(
"label"=>"Amount"
"type"=>"number",
"prefix"=>"$",
"decimals"=>2,
)
)
))
?>
name | type | default | description |
---|---|---|---|
label | string | Set label for column | |
type | string | Type of columns number ,string ,datetime | |
prefix | string | Set prefix for value, for example $ | |
suffix | string | Set suffix for value | |
formatValue | string/function | Accept string or function. For example: "formatValue"=>"@value USD" or "formatValue"=>function($value){return $value." USD";} | |
decimals | number | The number of number after decimal points | |
thousandSeparator | string | , | Specify how thousand is separated |
decimalPoint | string | . | Specify decimal point |
config | array | Contain special settings of chart js config for series, see below ChartJs configuration for column for more details | |
chartType | string | Specify which type of chart a column/series should be drawn as | |
axis | string | Specify which axis a column/series is measured against |
Since version 3.0.0, you can set Chartjs' dataset config directly in column settings instead of in column's config:
BarChart::create(array(
...
"columns" => array(
"column_1" => array(
...
"borderColor" => "blue", // set borderColor directly for column_1 instead of column_1's config
)
)
))
Config for column #
This is optional but we can have many further options/configs for the chart. Below are the properties that you can put under the config
.
<?php
LineChart::create(array(
"dataSource"=>$this->dataStore("category_amount"),
"columns"=>array(
"category",
"amount"=>array(
"label"=>"Amount"
"type"=>"number",
"prefix"=>"$",
"config"=>array(
"steppedLine"=>true
)
)
)
))
?>
name | type | default | description |
---|---|---|---|
backgroundColor | string | The fill color under the line. | |
borderColor | string | The color of the line | |
borderWidth | number | The width of the line in pixels. | |
borderDash | number[] | Length and spacing of dashes. | |
borderDashOffset | number | Offset for line dashes | |
borderCapStyle | string | Cap style of the line. | |
borderJoinStyle | string | Line joint style. | |
cubicInterpolationMode | string | Algorithm used to interpolate a smooth curve from the discrete data points. | |
fill | bool/string | How to fill the area under the line. | |
lineTension | number | Bezier curve tension of the line. Set to 0 to draw straight lines. This option is ignored if monotone cubic interpolation is used. | |
pointBackgroundColor | number/number[] | The fill color for points. | |
pointBorderColor | string/string[] | The border color for points. | |
pointBorderWidth | number/array | The width of the point border in pixels. | |
pointRadius | number/array | The radius of the point shape. If set to 0, the point is not rendered. | |
pointStyle | string/array | Style of the point. | |
pointHitRadius | number/array | The pixel size of the non-displayed point that reacts to mouse events.d | |
pointHoverBackgroundColor | string/array | Point background color when hovered. | |
pointHoverBorderColor | string/array | Point border color when hovered. | |
pointHoverBorderWidth | number/array | Border width of point when hovered. | |
pointHoverRadius | number/array | The radius of the point when hovered. | |
showLine | bool | If false, the line is not drawn for this dataset. | |
spanGaps | bool | If true, lines will be drawn between points with no or null data. If false, points with NaN data will create a break in the line | |
steppedLine | bool/string | If the line is shown as a stepped line. Value: true , false , "before" , "after" . If the steppedLine value is set to anything other than false, lineTension will be ignored. |
Get started with KoolReport
KoolReport will help you to construct good php data report by gathering your data from multiple sources, transforming them into valuable insights, and finally visualizing them in stunning charts and graphs.