ColumnChart
Overview #
A column chart provides a way of showing data values represented as vertical bars. It is sometimes used to show trend data, and the comparison of multiple data sets side by side.
Code:
<?php
\koolreport\chartjs\ColumnChart::create(array(
"title"=>"Sale Report",
"dataSource"=>$this->dataStore('sales')
"columns"=>array(
"category",
"sale"=>array("label"=>"Sale","type"=>"number","prefix"=>"$"),
"cost"=>array("label"=>"Cost","type"=>"number","prefix"=>"$"),
"profit"=>array("label"=>"Profit","type"=>"number","prefix"=>"$"),
)
));
In above example, we use datastore category_amount
as the dataSource for ColumnChart. We set the title
for the chart to "Sale Amount On Each Category". We specify columns from datastore to be used for drawing chart. The first column category
will be acted as label for xAxis while amount
will be value for yAxis. We add extra settings for amount
columns to make dollar sign appear in front of number.
We may add more data column to columns
, for each added columns, new chart series will be added.
Settings #
name | type | default | description |
---|---|---|---|
name | Specify name of chart, it is optional | ||
dataSource | *required Specify the source for chart, accept DataStore, DataSource, Process and even array data in table or associate format. | ||
columns | array/mixed | Specify the list of columns will be used to draw chart | |
options | array | Specify extra options for charts, see extra options section for more details. | |
title | string | Title of the charts | |
backgroundOpacity | number | 0.5 | Specify opacity of bar background |
stacked | boolean | false | Specify if the series of chart will be stacked. |
axes | array | Defined multiple axes for your chart |
Data column settings #
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 eaxmple: "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 seperated |
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
)
)
))
ChartJs config for column #
name | type | default | description |
---|---|---|---|
borderColor | string/array | The color of the bar border. We may specify an array of colors if we want different color for each bar in the series | |
backgroundColor | string/array | The fill color of the bar. We may input an array of colors if we want different color for each bar in the series | |
borderWidth | number/array | The stroke width of the bar in pixels. | |
borderSkipped | string | Which edge to skip drawing the border for. bottom , top , left , right | |
hoverBackgroundColor | string/array | The fill colour of the bars when hovered. | |
hoverBorderColor | string/array | The stroke colour of the bars when hovered. | |
hoverBorderWidth | string/array | The stroke width of the bars when hovered. | |
xAxisID | string | The ID of the x axis to plot this dataset on. If not specified, this defaults to the ID of the first found x axis | |
yAxisID | string | The ID of the y axis to plot this dataset on. If not specified, this defaults to the ID of the first found y axis. |
Example for column settings:
ColumnChart::create(array(
"dataSource"=>$this->dataStore("category_amount"),
"title"=>"Sale Amount On Each Category"
"columns"=>array(
"category",
"amount"=>array(
"label"=>"Amount",
"type"=>"number",
"prefix"=>'$',
"config"=>array(
"borderColor"=>"#aaaaaa",
"backgroundColor"=>"#dddddd",
"borderWidth"=>2,
)
)
),
))
?>
Some extra options #
Below are some extra options for ColumnChart. This below settings are put under options
property.
name | type | default | description |
---|---|---|---|
barPercentage | number | 0.9 | Percent (0-1) of the available width each bar should be within the category width. 1.0 will take the whole category width and put the bars right next to each other. |
categoryPercentage | number | 0.8 | Percent (0-1) of the available width each category should be within the sample width. |
barThickness | number | Manually set width of each bar in pixels. If not set, the base sample widths are calculated automatically so that they take the full available widths without overlap. Then, the bars are sized using barPercentage and categoryPercentage. | |
maxBarThickness | Set this to ensure that bars are not sized thicker than this. |
Stacked chart #
ColumnChart support stacked chart
Code:
<?php
ColumnChart::create(array(
...
"stacked"=>true
))
?>
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.