Tooltip Format

The above example shows you how to create LineChart 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 line chart with tooltip format.

Set format for the value of each data in tooltip.

Specified function receives name, ratio, id and index of the data point to show. ratio will be undefined if the chart is not donut/pie/gauge.

If undefined returned, the row of that value will be skipped.

Default: undefined

For example:

...
"options" => array(
    ...
    "tooltip" => array(
        "format" => array(
            "title" => "function (d) { return 'Data ' + d; }",
            "value" => "function (value, ratio, id) {
                var format = id === 'data1' ? d3.format(',') : d3.format('$');
                return format(value);
            }"
        )
    )
)
<?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'>Tooltip Format</h1>
<?php
$data = [
    ['data1' =>  30000, 'data2' => 100],
    ['data1' =>  20000, 'data2' => 200],
    ['data1' =>  10000, 'data2' => 100],
    ['data1' =>  40000, 'data2' => 40],
    ['data1' =>  15000, 'data2' => 150],
    ['data1' => 250000, 'data2' => 250]
];

\koolreport\d3\LineChart::create(array(
    "dataSource" => $data,
    "columns" => array(
        'data1',
        'data2',
    ),
    "options" => array(
        "data" => array(
            "axes" => array(
                "data2" => 'y2'
            )
        ),
        "axis" => array(
            "y" => array(
                "tick" => array(
                    "format" => "function(value) {
                        var format = d3.format(\"s\");
                        return format(value);
                    }"
                )
            ),
            "y2" => array(
                "show" => true,
                "tick" => array(
                    "format" => "function(value) {
                        var format = d3.format(\"$\");
                        return format(value);
                    }"
                )
            )
        ),
        "tooltip" => array(
            "format" => array(
                "title" => "function (d) { return 'Data ' + d; }",
                "value" => "function (value, ratio, id) {
                    var format = id === 'data1' ? d3.format(',') : d3.format('$');
                    return format(value);
                }"
            )
        )
    )
));

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