PHP Tutorial

PHP Flow Control

PHP Functions

PHP String

PHP Array

PHP Date Time

PHP Object Oriented

Regular Expression

PHP Cookie & Session

PHP Error & Exception handling

MySQL in PHP

PHP File Directory

PHP Image Processing

PHP Uses JpGraph To Create Images

JpGraph is an Object-Oriented Graph creating library for PHP. The library is completely written in PHP and ready to be used in any PHP scripts.

Here is a simple example on how to create a basic bar plot using JpGraph:

First, you need to include the JpGraph library. You can download it from the official JpGraph website. After downloading and installing, you can include it in your PHP script.

require_once ('jpgraph/src/jpgraph.php');
require_once ('jpgraph/src/jpgraph_bar.php');

Next, you can create the data that you want to plot:

$datay=array(12,8,19,3,10,5);

Then, you create a new graph:

// Create the graph. 
$graph = new Graph(350,250);

Next, you set the scale for the graph:

$graph->SetScale('textlin');

After that, you can customize the graph, like setting titles:

$graph->title->Set('A simple bar graph');

Then, you create a new bar plot with your data:

$bplot = new BarPlot($datay);

You can also customize the plot, like setting its color:

$bplot->SetFillColor('orange');

Next, you add the plot to the graph:

$graph->Add($bplot);

Finally, you output the graph to the browser:

$graph->Stroke();

So, the complete script would look like this:

<?php
require_once ('jpgraph/src/jpgraph.php');
require_once ('jpgraph/src/jpgraph_bar.php');

$datay=array(12,8,19,3,10,5);

// Create the graph. 
$graph = new Graph(350,250);
$graph->SetScale('textlin');

$graph->title->Set('A simple bar graph');

$bplot = new BarPlot($datay);

$bplot->SetFillColor('orange');

$graph->Add($bplot);

$graph->Stroke();
?>

This script will create a simple bar graph with the provided data.

Remember, for the JpGraph library to work, the GD library must be enabled in your PHP installation. The GD library is an open source code library for the dynamic creation of images by programmers. GD is written in C, and "wrappers" are available for Perl, PHP and other languages. GD creates PNG, JPEG and GIF images, among other formats.

  1. How to Install and Set Up JpGraph in PHP:

    JpGraph is a PHP library for creating graphs. You can install it using Composer:

    composer require jpgraph/jpgraph
    

    After installation, include the autoload file in your PHP script:

    <?php
    require_once __DIR__ . '/vendor/autoload.php';
    
  2. PHP JpGraph Examples for Bar Charts:

    Create a simple bar chart using JpGraph.

    <?php
    require_once __DIR__ . '/vendor/autoload.php';
    
    $data = [40, 70, 90, 30, 50];
    
    $graph = new Graph\Graph(400, 300);
    $graph->SetScale('textlin');
    $graph->title->Set('Bar Chart Example');
    
    $barplot = new Plot\BarPlot($data);
    $graph->Add($barplot);
    
    $graph->Stroke();