PHPackages                             fbohorquez/sql-charts-dashboard - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. fbohorquez/sql-charts-dashboard

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

fbohorquez/sql-charts-dashboard
===============================

Simple PHP library for create SQL charts dashboard

234PHP

Since Jul 6Pushed 7y ago1 watchersCompare

[ Source](https://github.com/fbohorquez/sql-charts-dashboard)[ Packagist](https://packagist.org/packages/fbohorquez/sql-charts-dashboard)[ RSS](/packages/fbohorquez-sql-charts-dashboard/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

[ ![dev2bit](https://raw.githubusercontent.com/fbohorquez/sql-charts-dashboard/master/resources/logo.png)](https://www.dev2bit.com)

sql-charts-dashboard
====================

[](#sql-charts-dashboard)

Simple PHP library for create SQL charts dashboard

Requirements
------------

[](#requirements)

- [PHP 5.4.0 or higher](http://www.php.net/)

Installation
------------

[](#installation)

You can use **Composer** or simply **Download the Release**

### Composer

[](#composer)

The preferred method is via [composer](https://getcomposer.org). Follow the [installation instructions](https://getcomposer.org/doc/00-intro.md) if you do not already have composer installed.

Once composer is installed, execute the following command in your project root to install this library:

```
composer require fbohorquez/sql-charts-dashboard
```

Finally, be sure to include the autoloader:

```
require_once '/path/to/your-project/vendor/autoload.php';
```

### Download the Release

[](#download-the-release)

If you abhor using composer, you can download the package in its entirety. The [Releases](https://github.com/fbohorquez/sql-charts-dashboard/releases) page lists all stable versions. Download any file with the name `sql-charts-dashboard-[RELEASE_NAME].zip` for a package including this library and its dependencies.

Uncompress the zip file you download, and include the autoloader in your project:

```
require_once '/path/to/sql-charts-dashboard/vendor/autoload.php';
```

Using SQL Charts Dashboard Library
----------------------------------

[](#using-sql-charts-dashboard-library)

### Connection

[](#connection)

Connection object is a connection to database system. The Connections are used by Query to access the data.

A Connection object has:

- database name
- user
- pass
- host
- engine

```
$c = new Connection ('database', 'user', 'pass', 'localhost', 'mysqli');
```

Today library has support for mysqli and pdo\_mysql modules. You can build yours class SQL engine implementing this [interface](https://github.com/fbohorquez/sql-charts-dashboard/blob/master/src/SqlChartsDashboard/SqlChartsDashboardInterface/SqlEngineInterface.php)

Also you can defined a default SQL engine to all connections in a dashboard.

```
Dashboard::setDefaultSqlEngine ('pdomysql');
$c = new Connection ('database', 'user', 'pass', 'localhost');
```

mysqli is init default SQL engine.

### Query

[](#query)

Query object is a SQL query. This is a SQL string and a connection to database system. Queries only call database one time, these cache results.

```
$c = new Connection ('database', 'user', 'pass', 'localhost');
$query = new Query ('SELECT state, COUNT(*) as n FROM offers GROUP BY state', $c);
```

You can defined a default Connection to all queries in a dashboard.

```
Dashboard::setDefaultConnection ('database', 'user', 'pass', 'localhost');
$query = new Query ('SELECT state, COUNT(*) as n FROM offers GROUP BY state');

//or

$c = new Connection ('database', 'user', 'pass', 'localhost');
Dashboard::setDefaultConnection ($c);
$query = new Query ('SELECT state, COUNT(*) as n FROM offers GROUP BY state');
```

### Charts

[](#charts)

Charts objects represent graphics that draw in client side. There severals [types of charts](https://github.com/fbohorquez/sql-charts-dashboard/tree/master/src/SqlChartsDashboard/ChartType): line, table, pie, area... You must take class corresponding to type of chart. A Chart has a title, Query and a columns defination.

```
$query = new Query ('SELECT state, COUNT(*) as n FROM offers GROUP BY state');
$chart = new ChartLine (
  'line-chart-example',
  $query,
  [
    'state' => [
        'type' => 'string',
        'label' => 'State',
    ],
    'n' => [
      'type' => 'number',
      'label' => 'Amount',
    ],
  ]
);
```

Keys of columns defination array must be fields in SQL query.

Default charts engine in client side is [google chart](https://developers.google.com/chart/) (gchart). Optionally you can construct charts with a distinct engine as last parameter in constructor.

Today library has support only for google charts. You can build yours class charts engine implementing this [interface](https://github.com/fbohorquez/sql-charts-dashboard/blob/master/src/SqlChartsDashboard/SqlChartsDashboardInterface/ChartsEngineInterface.php)

You can defined a default charts engine to all charts in a dashboard.

```
Dashboard::setDefaultChartsEngine ('gcharts');
```

Also you can set options to chart object. Options depends of chart engine.

```
$chart->setOptions (
  [
    'colors' => ['red'],
  ]
);
```

Also you can set a new query to chart.

```
$chart->setQuery ($query);
```

### Dashboard

[](#dashboard)

Dashboard object represent charts set. This has a title and chart object or charts objects array. Dashboard object has method html that return HTML string for response.

```
$dash = new Dashboard ('dashboard-example', $chart);
echo $dash->html();

//or

$dash = new Dashboard ('dashboard-example', [$chart0, $chart1, $chart2]);
echo $dash->html();
```

HTML is generated with simple view engine. This use concatenate strings for generate a clean struct HTML that contain charts. You can build your view engine implementing this [interface](https://github.com/fbohorquez/sql-charts-dashboard/blob/master/src/SqlChartsDashboard/SqlChartsDashboardInterface/ViewEngineInterface.php). Optionally you can construct dashboards with a distinct view engine as last parameter in constructor. Also you can defined a default view engine to all dashboards.

```
Dashboard::setDefaultViewEngine ('simple');
```

You can add new charts to dasboard.

```
$dashboard->addChart (
  (
    new ChartBar (
      'bar-chart-example',
      $query,
      [
        'state' => [
            'type' => 'string',
            'label' => 'State',
        ],
        'n' => [
          'type' => 'number',
          'label' => 'Amount',
        ],
      ]
    )
  )
);
```

Example
-------

[](#example)

```
use SqlChartsDashboard\Dashboard;
use SqlChartsDashboard\Query;
use SqlChartsDashboard\ChartType\ChartLine;
use SqlChartsDashboard\ChartType\ChartBar;

Dashboard::setDefaultConnection ('database', 'user', 'pass', 'localhost');

$query = new Query ('SELECT state, COUNT(*) as n, MAX(pvp) as pvp FROM offers GROUP BY state');

echo (
    new Dashboard (
      'example',
      [
        ( // chart0
          new ChartLine (
            'line-chart-example',
            $query,
            [
              'state' => [
                  'type' => 'string',
                  'label' => 'State',
              ],
              'n' => [
                'type' => 'number',
                'label' => 'Amount',
              ],
            ]
          )
        ),
        ( // chart1
          (new ChartBar ('bar-chart-example'))
          ->setQuery ($query)
          ->setColumns (
            [
              'state' => [
                  'type' => 'string',
                  'label' => 'State',
              ],
              'pvp' => [
                'type' => 'number',
                'label' => 'Max PVP',
              ],
            ]
          )
          ->setOptions (
            [
              'colors' => ['red'],
            ]
          )
        )

      ]
    )
)->html();
```

[![example](https://raw.githubusercontent.com/fbohorquez/sql-charts-dashboard/master/resources/example.png)](https://raw.githubusercontent.com/fbohorquez/sql-charts-dashboard/master/resources/example.png)

Autor
-----

[](#autor)

Francisco Javier Bohórquez Ogalla

Developed with ♥ by [dev2bit](https://www.dev2bit.com)

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3486d46b7a7f5dc287f3c68f0cf770de08126ae9efe7e3b70afbf58ac35c4b46?d=identicon)[fbohorquez](/maintainers/fbohorquez)

### Embed Badge

![Health badge](/badges/fbohorquez-sql-charts-dashboard/health.svg)

```
[![Health](https://phpackages.com/badges/fbohorquez-sql-charts-dashboard/health.svg)](https://phpackages.com/packages/fbohorquez-sql-charts-dashboard)
```

###  Alternatives

[onokumus/metismenujs

A menu plugin

13210.2k](/packages/onokumus-metismenujs)[noximo/php-colored-ascii-linechart

Pretty line graphs in your console, html or images

1994.1k](/packages/noximo-php-colored-ascii-linechart)[magestat/module-floating-buy-button

Get your customer attention the most important action in your online store, the purchase.

121.6k](/packages/magestat-module-floating-buy-button)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
