PHP code example of lfiweb / jsonstat-phpviz

1. Go to this page and download the library: Download lfiweb/jsonstat-phpviz library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lfiweb / jsonstat-phpviz example snippets




use jsonstatPhpViz\Reader;
use jsonstatPhpViz\Renderer\TableHtml;

tat = json_decode($json);

$reader = new Reader($jsonstat);
$table = new TableHtml($reader);
$html = $table->render();

$reader = new Reader($jsonstat);
$table = new TableHtml($reader, 3);
$html = $table->render();

$reader = new Reader($jsonstat);
$axes = [3, 1, 2, 0];
$reader->transpose($axes);
$table = new TableHtml($reader);
$html = $table->render();

$reader = new Reader($jsonstat);
$table = new TableHtml($reader);
$table->excludeOneDim = true;
$table->noLabelLastDim = true;
$html = $table->render();

$reader = new Reader($jsonstat);
$table = new \jsonstatPhpViz\Renderer\TableTsv($reader);
$table->separatorCol = ",";
$html = $table->render();

class MyRendererTable extends TableHtml
{
    /**
     * Override with the new html cell renderer.
     * @return void
     */
    protected function newCellRenderer(): CellInterface
    {
        $formatter = new FormatterCell($this->reader);
        return new MyCellHtml($formatter, $this->reader, $this);
    }
}

class MyCellHtml extends CellHtml
{
    // render html inside label (header) cells
    public function addCellHeader(DOMElement $row, ?string $str = null, ?string $scope = null, ?string $colspan = null, ?string $rowspan = null): DOMElement
    {
        $cell = parent::headerCell($row, $str, $scope, $colspan, $rowspan);
        $cell->textContent = '';
        UtilHtml::append($cell, $str);

        return $cell;
    }
}