PHP Classes

PHP Plot Chart: Generate chart image from a list of data points

Recommend this page to a friend!
  Info   Example   Screenshots   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: 76 All time: 10,177 This week: 49Up
Version License PHP version Categories
php-plotchart 1.0Custom (specified...5HTML, PHP 5, Graphics
Description 

Author

This package can generate chart images from a list of data points.

It can take an array with data points and other values that define parameters of the way the chart can be visually rendered.

The package can process the data points and generate a drawing image that shows a chart with those points.

It generates HTML with tags that can be used on a page to show the generated image.

The generated image data is embedded in the rendered HTML.

Picture of Win Aung Cho
  Performance   Level  
Name: Win Aung Cho <contact>
Classes: 11 packages by
Country: Myanmar Myanmar
Innovation award
Innovation award
Nominee: 3x

Example

<?php
include("plotChart.php");
   
$data = [
       
u => [
            [-
100, -45000],
            [
0, 60000],
            [
200, 360000],
            [
400, -260000],
            [
480, 80000]
        ]
    ];
    echo
"<h1>Usage 1</h1>";
   
$plotchart = new PlotChart();
   
$plotchart->fitGraph($data);
   
$plotchart->plotGraph($data);
   
$plotchart->viewImage();
?>


Details

PHP-PlotChart

This class generate chart image with various options defined by associative array (JSON). PHP-PlotChart

Data

Chart drawing settings and plot data are prepared using associative array. Default associative keys are shown bellow.

Chart setting

    // data for chart setting
    $setting = [
        imgw => 600,  // width of image
        imgh => 400,  // height of image
        // margin to plot area
        mgright => 50,
        mgtop => 80,
        mgleft => 80,
        mgbot => 80,
        // text sizes
        tgrid => 15,
        tstitle => 20,
        ttitle => 25,
        
        psize => 10, // point size
        // number of grid lines
        ngx => 10, 
        ngy => 10,
        // color for chart
        text_rgb => '649696',
        title_rgb => '0000FA',
        stitle_rgb => '009696',
        line_rgb => 'E90E5B',
        grid_rgb => '808080',
        axis_rgb => '000000',
        back_rgb => 'FAFAFA',
        chart_rgb => 'EDEDED',
        
        // String of titles
        strtitle => "This is TITLE",
        strstitle => "Subtitle",
        strstitlex => "Title X",
        strstitley => "Title Y"
    ];

Data to be plotted

    // Data to be ploted
    $data = [
        // drawing options
        pointmode => 0,
        drawline => true,
        drawvert => false,
        drawhorz => false,
        showvalue => false,
        // drawing colors
        line_color => 'E90E5B',
        hline_color => 'E90E5B',
        vline_color => 'E90E5B',
        value_color => '649696',
        // data to be ploted
        u => [
            [-100, -45000], 
            [0, 60000], 
            [200, 360000], 
            [400, -260000], 
            [480, 80000]
        ]
    ];

Data example

Example 1

    // example 1 Basic data for minimum requirement
    $data = [
        u => [
            [-100, -45000], 
            [0, 60000], 
            [200, 360000], 
            [400, -260000], 
            [480, 80000]
        ]
    ];

Example 2

    // example 2 Data with some options
    $data = [
        showvalue => true, 
        pointmode => 1, 
        drawvert => true, 
        drawline => false, 
        color => 'AA0000', 
        value_color => '000000',
        u => [
            [-100, -45000], 
            [0, 60000], 
            [200, 360000], 
            [400, -260000], 
            [480, 80000]
        ]
    ];

Example 3

    // example 3 Data to change chart settings
    $setting = [
        "strtitle" => "Title is updated", 
        strstitle => "Subtitle", 
        ngy => 7, 
        ngx => 10
    ];

Example 4 Example for sine function

    // example 4
    $f = [];
    for ($i = 0;$i < 40;$i++)
    {
        $A = 10;
        $B = 400000;
        $f[u][$i][0] = $A*$i;
        $f[u][$i][1] = $B sin($A$i * 3.1415 / 180.0);
    }
  

Usage of PlotChart

Usage 1

    // usage 1 
    // add + example 1
    $plotchart = new PlotChart();
    $plotchart->fitGraph($data);
    $plotchart->plotGraph($data);
    $plotchart->viewImage();

PHP-PlotChart

Usage 2

    // usage 2
    // add + example 4
    $plotchart = new PlotChart();
    $plotchart->fitGraph($f);
    $plotchart->plotGraph($f);
    $plotchart->viewImage();

PHP-PlotChart

Usage 3

    // usage 3
    // add + example 1 + example 3
    $plotchart = new PlotChart($setting);
    $plotchart->fitGraph($data);
    $plotchart->drawGrid();
    $plotchart->plotGraph($data);
    $plotchart->viewImage();

PHP-PlotChart

Usage 4

    // usage 4
    // add + example 2 + example 3 + example 4
    $plotchart = new PlotChart($setting);
    $plotchart->fitGraph($data);
    $plotchart->fitGraph($f);
    $plotchart->drawGrid();
    $plotchart->plotGraph($data);
    $plotchart->plotGraph($f);
    $plotchart->viewImage();

PHP-PlotChart

Contact

Contact me for comercial use via mail winaungcho@gmail.com.


Screenshots (4)  
  • usage1.png
  • usage2.png
  • usage3.png
  • usage4.png
  Files folder image Files (15)  
File Role Description
Files folder imageimages (4 files)
Files folder imagesrc (5 files)
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (15)  /  images  
File Role Description
  Accessible without login Image file usage1.png Icon Icon image
  Accessible without login Image file usage2.png Icon Icon image
  Accessible without login Image file usage3.png Icon Icon image
  Accessible without login Image file usage4.png Icon Icon image

  Files folder image Files (15)  /  src  
File Role Description
  Plain text file plotChart.php Class Class source
  Accessible without login Plain text file usage1.php Example Example script
  Accessible without login Plain text file usage2.php Example Example script
  Accessible without login Plain text file usage3.php Example Example script
  Accessible without login Plain text file usage4.php Example Example script

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  
 73%
Total:76
This week:0
All time:10,177
This week:49Up
User Comments (1)