Charts

Warning: Undefined variable $description in /customers/7/a/f/reportico.org/httpd.www/reports8/examples/content.php on line 2

Warning: Undefined variable $description in /customers/7/a/f/reportico.org/httpd.www/reports8/examples/content.php on line 9


Generate charts inside your output

The chart method() allows you to place a chart visualising the data for the report or for each group section. You are able to set the chart tiele, axes titles, legend title.

Usage:
 
\Reportico\Engine\Builder\build
()
  ->
chart(groupcolumn :If specified the group column after which to add a chart)
    ->
title(title :Title Of Chart)
    ->
plot(column :Column to Plot)
    ->
plotType(column [bar|pie|line|stackedbar])
    ->
legend(legend :Text label of the plot column to place in the legend box)
    ->
xlabels(column :Name of column containing the labels for the X axis)
    ->
xtitle(title :X Axis Title)
    ->
ytitle(title :Y Axis Title)



In this example, the group feature is used to produce a section per product category and the chart method takes the group name to indicate that a chart should be presented after each category section. If you want a single chart at the end of the report do not specify any parameter to the chart() method. The example shows how to set the chart and axis titles, add columns to plot and add legends.

Run Demo


<?php
      
require_once(__DIR__ .'/../vendor/autoload.php');

     
      
\Reportico\Engine\Builder::build()
          ->
properties([ "bootstrap_preloaded" => true])
          ->
datasource()->database("mysql:host=localhost; dbname=DATABASE NAME")->user("USER")->password("PASSWORD")
          ->
title     ("Product Stock")
          ->
description     ("Produces a list and charts of stock levels")
          ->
sql       ("
              SELECT  ProductID id, ProductName product, UnitsInStock in_stock, ReorderLevel reorder_level, companyname Company, country, categoryname category
              FROM northwind_products 
              join northwind_suppliers on northwind_products.supplierid = northwind_suppliers.supplierid
              join northwind_categories on northwind_products.categoryid = northwind_categories.categoryid
              WHERE 1 = 1  
              ORDER BY categoryname
                "
)
          ->
group("category")
              ->
header("category")
              ->
throwPageBefore()
          ->
chart("category")
              ->
title("Stock Levels")
              ->
plot("in_stock")->plotType("bar")->legend("In stock")
              ->
plot("reorder_level")->plotType("line")->legend("Reorder Level")
              ->
xlabels("product")
              ->
xtitle("Levels")
              ->
ytitle("Products")
          ->
prepare();
?>