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 TableTsv($reader);
$table->separatorCol = ",";
$html = $table->render();

class MyCellHtml extends CellHtml
{

    /**
     * Append the label as a HTML fragment and escape potential entities.
     *
     * The label is data and may contain characters such as '<' (e.g. '<1%'), which is not valid
     * markup and would make UtilHtml::append() insert plain text. The data is therefore
     * escaped before the markup of the formatter is added.
     * @param ?String $label cell content
     * @return DOMElement table cell element
     * @throws DOMException
     */
    protected function addCellHeader(?string $label = null): DOMNode
    {
        $cell = parent::addCellHeader($label);
        if ($label !== null) {
            $cell->textContent = '';
            $label = UtilHtml::escape($label);
            $label = $this->table->formatter->formatHeaderCell($label);
            UtilHtml::append($cell, $label);
        }

        return $cell;
    }
}

$table = new TableHtml($reader);
$table->formatter = new FormatterCell($table->reader);