PHP Classes

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

Recommend this page to a friend!

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


  Detailed description   Download Download .zip .tar.gz  
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.

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.


  Classes of Win Aung Cho  >  PHP Plot Chart  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: PHP Plot Chart
Base name: php-plotchart
Description: Generate chart image from a list of data points
Version: 1.0
PHP version: 5
License: Custom (specified in a license file)
 
  Groups   Screenshots Screenshots   Applications   Files Files  

  Groups  
Group folder image HTML HTML generation and processing View top rated classes
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image Graphics Colors, images, charts and picture formats View top rated classes

  Files folder image Screenshots  
usage1.png
File Role Description
Accessible without login Image file usage1.png Screen Usage of plotchart
Accessible without login Image file usage2.png Screen Usage of plotchart
Accessible without login Image file usage3.png Screen Usage of plotchart
Accessible without login Image file usage4.png Screen Usage of plotchart


  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
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  /  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  /  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

Download Download all files: php-plotchart.tar.gz php-plotchart.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
  Files folder image Files  
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  /  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  /  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

Download Download all files: php-plotchart.tar.gz php-plotchart.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.