Data Label Format

The above example shows you how to create ColumnChart using D3 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.

The example show how to create column chart with custom data label.

Set formatter function for data labels.

The formatter function receives 4 arguments such as v, id, i, j and it must return a string that will be shown as the label. The arguments are:

v is the value of the data point where the label is shown.

id is the id of the data where the label is shown.

i is the index of the data point where the label is shown.

j is the sub index of the data point where the label is shown.

For example:

...
"options" => array(
    "data" => array(
        ...
        "labels" => array(
            "format" => array(
                "data1" => "function (v, id, i, j) { 
                        return '$' + v; 
                    }"
            )
        )
    ),
    ...
)
<?php
require_once "../../../../load.koolreport.php";
require_once "MyReport.php";
$report = new MyReport;
$report->run();
$report->render();
<?php

class MyReport extends \koolreport\KoolReport
{

}
<h1 class='title'>Data Label Format</h1>
<?php
$data = [
    ['data1' =>   30, 'data2' =>  -50, 'data3' => -100],
    ['data1' => -200, 'data2' =>  150, 'data3' =>  100],
    ['data1' => -100, 'data2' => -150, 'data3' =>  -40],
    ['data1' =>  400, 'data2' =>  150, 'data3' =>  100],
    ['data1' =>  150, 'data2' =>  -50, 'data3' => -150],
    ['data1' =>  250, 'data2' => -150, 'data3' =>  -50]
];

\koolreport\d3\ColumnChart::create(array(
    "dataSource" => $data,
    "columns" => array(
        'data1',
        'data2',
        'data3'
    ),
    "options" => array(
        "data" => array(
            "groups" => array(
                array(
                    "data1",
                    "data2"
                )
            ),
            "labels" => array(
                "format" => array(
                    "data1" => "function (v, id, i, j) { 
                            return '$' + v; 
                        }"
                )
            )
        ),
        "grid" => array(
            "y" => array(
                "lines" => array(
                    array(
                        "value" => 0
                    )
                )
            )
        )
    )
));

What People Are Saying

"KoolReport helps me very much in creating data report for my corporate! Keep up your good work!"
-- Alain Melsens

"The first use of your product. I was impressed by its easiness and powerfulness. This product is a great and amazing."
-- Dr. Lew Choy Onn

"Fantastic framework for reporting!"
-- Greg Schneider

Download KoolReport Get KoolReport Pro