PHP Classes

PHP Stats Graphs: Generate SVG charts from sample data

Recommend this page to a friend!
  Info   Example   Demos   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 279 All time: 7,625 This week: 524Up
Version License PHP version Categories
simple-stats 1.0.0MIT/X Consortium ...5.3.9PHP 5, Graphics, Statistics
Description 

Author

This package can generate SVG charts from sample data from a database.

It can data read from a database and generates charts of different types from that data. Currently it provides classes to generate bar and scatter charts.

The database with the data is defined by external configuration file.

Currently the package provides a seed command class that populates the database with random data, but another command class could be used to generate the data for the charts.

Picture of Joseluis Laso
  Performance   Level  
Name: Joseluis Laso <contact>
Classes: 16 packages by
Country: Spain Spain
Age: 56
All time rank: 92219 in Spain Spain
Week rank: 180 Up6 in Spain Spain Up
Innovation award
Innovation award
Nominee: 6x

Winner: 2x

Example

#!/usr/bin/env php
<?php

namespace JLaso\SimpleStats;

require_once
__DIR__ . '/../vendor/autoload.php';

use
JLaso\SimpleStats\Command\GenGraphCommand;
use
JLaso\SimpleStats\Command\SeedCommand;
use
Symfony\Component\Yaml\Yaml;
use
Symfony\Component\Console\Application;

$application = new Application();
$application->addCommands(
    array(
        new
SeedCommand(),
        new
GenGraphCommand(),
    )
);
$application->run();


Details

simple-stats

A simple system to log events in your PHP app

Installation

You need only to require this package in your project `composer require jlaso/simple-stats`

Configuration (optional)

In order to let know the library where it can put it's database file and other things related with setup you can copy the distribution file config-stats-base.yml.dist in the root of your project with the config-stats-base.yml

This file contains:

database:
    driver: pdo_sqlite
    path: "%project_dir%/app/cache/simple_stats.sqlite"
    charset: UTF8    

models:
    - clicks
    - ips
    - logins

The database key configures how the sqlite will work, and the models key informs SimpleStats about the events we want to register. Any change on any of these keys requires remove the sqlite database file in order that SimpleStats recreates new one.

For the moment no migration process is allowed.

Info

That library uses svg files in order to show the results of the statistics.

Commands

In order to check the examples I provided a couple of commands that you can start from terminal

Create demo data

Create thousand of records in every event table with invented data.


### Create a graph svg file with the data

src/console graph:create --graph=scatter --event="clicks,ips,logins" --title="Events by day" open temp.svg.html


As you can see you can just pass one event table or several separated by commas.
The output default file is temp.svg.html.

## Graphs provided

As I told you the system uses a third party SVG library in order to represent statistical data.

For the moment there are this graph available:

## Bar

Use: Data ordered in a bar or piles way 

![](doc/images/example-bars.png)

## Scatter

Use: Data with X reference (2d) with one or several dimensions 

![](doc/images/example-scatter.png)

# Running the examples

Go to terminal and start PHP listening in the root folder of the project ```php -S localhost:8000```

Now you can go with your favourite browser to http://localhost:8000/samples/index.html

For the moment there are two examples. You have to see the same data in both, but using different technology. Just to show you
how easy is to use this library.



  Live demoExternal page  
  Files folder image Files (24)  
File Role Description
Files folder imagedoc (1 directory)
Files folder imagesamples (2 files, 2 directories)
Files folder imagesrc (3 files, 3 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file config-stats-base.yml.dist Data Auxiliary data
Accessible without login Plain text file demo.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (24)  /  doc  
File Role Description
Files folder imageimages (2 files)

  Files folder image Files (24)  /  doc  /  images  
File Role Description
  Accessible without login Image file example-bars.png Data Auxiliary data
  Accessible without login Image file example-scatter.png Icon Icon image

  Files folder image Files (24)  /  samples  
File Role Description
Files folder imageplain-php (1 file)
Files folder imagetwig (2 files)
  Accessible without login Plain text file click.php Example Example script
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files (24)  /  samples  /  plain-php  
File Role Description
  Accessible without login Plain text file demo.php Example Example script

  Files folder image Files (24)  /  samples  /  twig  
File Role Description
  Accessible without login Plain text file demo.html.twig Data Auxiliary data
  Accessible without login Plain text file demo.php Example Example script

  Files folder image Files (24)  /  src  
File Role Description
Files folder imageCommand (2 files)
Files folder imageGraph (4 files)
Files folder imageModel (3 files)
  Accessible without login Plain text file console Example Example script
  Accessible without login Plain text file Stats.php Class Class source
  Accessible without login Plain text file StatsBase.php Class Class source

  Files folder image Files (24)  /  src  /  Command  
File Role Description
  Accessible without login Plain text file GenGraphCommand.php Class Class source
  Accessible without login Plain text file SeedCommand.php Class Class source

  Files folder image Files (24)  /  src  /  Graph  
File Role Description
  Accessible without login Plain text file Bar.php Class Class source
  Accessible without login Plain text file BaseGraph.php Class Class source
  Accessible without login Plain text file GraphInterface.php Class Class source
  Accessible without login Plain text file Scatter.php Class Class source

  Files folder image Files (24)  /  src  /  Model  
File Role Description
  Accessible without login Plain text file DB.php Class Class source
  Accessible without login Plain text file Event.php Class Class source
  Accessible without login Plain text file StatsModel.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:279
This week:0
All time:7,625
This week:524Up