PHP Classes

PHP PDF Line Chart: Generate line charts to compare data in PDF

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
StarStarStarStarStar 80%Total: 414 All time: 6,457 This week: 35Up
Version License PHP version Categories
php2pdfgraphcompare 1.1GNU General Publi...4Graphics, Files and Folders, Printing
Description 

Author

This class can generate line charts to compare data in PDF.

It extends the FPDF class to add line charts to a PDF document from a given data set to allow each set of values to be visually compared.

The class takes as parameters the title, position coordinates and size of the chart to be added to the PDF document.

Innovation Award
PHP Programming Innovation award nominee
March 2016
Number 7


Prize: One downloadable copy of Komodo IDE
PDF is a popular format to generate documents that are meant to be printed.

Sometimes it is necessary to display charts on documents to be printed.

This class can generate PDF documents that show line charts to compare multiple sets of data.

Manuel Lemos
Picture of Luciano Salvino
  Performance   Level  
Name: Luciano Salvino <contact>
Classes: 11 packages by
Country: Argentina Argentina
Age: 51
All time rank: 134316 in Argentina Argentina
Week rank: 170 Up3 in Argentina Argentina Up
Innovation award
Innovation award
Nominee: 9x

Example

<?php

include('PHP2PDFGraphCompare.php');

$pdf = new PDF( '$p_orient', 'mm', '$p_size' );
$pdf->Open();
$pdf->AddPage();

// define position
$y = 30;
$w = ($pdf->w - 20);
$h = 80;
$x = 15;
   
// define title
$repTitle = "Visits";
               
$arrData = array();

// define old data
$arrData[] = array(
   
"title" => "3 Months Ago",
   
"color" => array(255,22,0),
   
"data" => array(
        array(
           
"key" => 1,
           
"value" => 3500
       
),
        array(
           
"key" => 2,
           
"value" => 900
       
),
        array(
           
"key" => 3,
           
"value" => 4100
       
),
        array(
           
"key" => 4,
           
"value" => 4100
       
),
        array(
           
"key" => 5,
           
"value" => 4000
       
),
        array(
           
"key" => 6,
           
"value" => 3700
       
),
        array(
           
"key" => 7,
           
"value" => 3100
       
),
        array(
           
"key" => 8,
           
"value" => 3900
       
),
        array(
           
"key" => 9,
           
"value" => 3200
       
),
        array(
           
"key" => 10,
           
"value" => 2850
       
),
    )
);
// define old data
$arrData[] = array(
   
"title" => "2 Months Ago",
   
"color" => array(0,137,197),
   
"data" => array(
        array(
           
"key" => 1,
           
"value" => 2500
       
),
        array(
           
"key" => 2,
           
"value" => 1900
       
),
        array(
           
"key" => 3,
           
"value" => 3200
       
),
        array(
           
"key" => 4,
           
"value" => 3100
       
),
        array(
           
"key" => 5,
           
"value" => 3000
       
),
        array(
           
"key" => 6,
           
"value" => 2700
       
),
        array(
           
"key" => 7,
           
"value" => 2100
       
),
        array(
           
"key" => 8,
           
"value" => 1900
       
),
        array(
           
"key" => 9,
           
"value" => 2200
       
),
        array(
           
"key" => 10,
           
"value" => 3210
       
),
    )
);
// define old data
$arrData[] = array(
   
"title" => "Last Month",
   
"color" => array(55,00,122),
   
"data" => array(
        array(
           
"key" => 1,
           
"value" => 800
       
),
        array(
           
"key" => 2,
           
"value" => 3100
       
),
        array(
           
"key" => 3,
           
"value" => 2700
       
),
        array(
           
"key" => 4,
           
"value" => 2100
       
),
        array(
           
"key" => 5,
           
"value" => 2000
       
),
        array(
           
"key" => 6,
           
"value" => 2700
       
),
        array(
           
"key" => 7,
           
"value" => 3000
       
),
        array(
           
"key" => 8,
           
"value" => 3600
       
),
        array(
           
"key" => 9,
           
"value" => 3250
       
),
        array(
           
"key" => 10,
           
"value" => 3150
       
),
    )
);
// define current data
$arrData[] = array(
   
"title" => "Current",
   
"color" => array(237,125,22),
   
"data" => array(
        array(
           
"key" => 1,
           
"value" => 1800
       
),
        array(
           
"key" => 2,
           
"value" => 2900
       
),
        array(
           
"key" => 3,
           
"value" => 3700
       
),
        array(
           
"key" => 4,
           
"value" => 3100
       
),
        array(
           
"key" => 5,
           
"value" => 4100
       
),
        array(
           
"key" => 6,
           
"value" => 3800
       
),
        array(
           
"key" => 7,
           
"value" => 3900
       
),
        array(
           
"key" => 8,
           
"value" => 3600
       
),
        array(
           
"key" => 9,
           
"value" => 3800
       
),
        array(
           
"key" => 10,
           
"value" => 3750
       
),
    )
);
// gen line charts
$pdf->LineChart($x,$y,$w,$h,$repTitle,$arrData);

// gen pdf file
$pdf->Output();


Details

PHP2PDFGraphCompare

PHP2PDFGraphCompare is a PHP class that create PDF file with line graph comparatives like google analytics. FPDF class extended

Usage

$pdf = new PDF( '$p_orient', 'mm', '$p_size' );
$pdf->Open();
$pdf->AddPage();

// define position and dimentions
$x = 15;
$y = 30; 
$w = ($pdf->w - 20);
$h = 80;
	
// define title	
$repTitle = "Visits";
				
$arrData = array();

// define old data
$arrData[] = array(
	"title" => "Last Month",
	"color" => array(55,00,122),
	"data" => array(
		array(
			"key"   => 1,
			"value" => 800
		),
		array(
			"key"   => 2,
			"value" => 3100
		),
		array(
			"key"   => 3,
			"value" => 2700
		),
		array(
			"key"   => 4,
			"value" => 2100
		),
		array(
			"key"   => 5,
			"value" => 2000
		),
		array(
			"key"   => 6,
			"value" => 2700
		),
		array(
			"key"   => 7,
			"value" => 3000
		),
		array(
			"key"   => 8,
			"value" => 3600
		),
		array(
			"key"   => 9,
			"value" => 3250
		),
		array(
			"key"   => 10,
			"value" => 3150
		),
	)
);
// define current data
$arrData[] = array(
	"title" => "Current",
	"color" => array(237,125,22),
	"data" => array(
		array(
			"key"   => 1,
			"value" => 1800
		),
		array(
			"key"   => 2,
			"value" => 2900
		),
		array(
			"key"   => 3,
			"value" => 3700
		),
		array(
			"key"   => 4,
			"value" => 3100
		),
		array(
			"key"   => 5,
			"value" => 4100
		),
		array(
			"key"   => 6,
			"value" => 3800
		),
		array(
			"key"   => 7,
			"value" => 3900
		),
		array(
			"key"   => 8,
			"value" => 3600
		),
		array(
			"key"   => 9,
			"value" => 3800
		),
		array(
			"key"   => 10,
			"value" => 3750
		),
	)
);
// gen line charts
$pdf->LineChart($x,$y,$w,$h,$repTitle,$arrData);

// gen pdf file
$pdf->Output();

Screenshots (1)  
  • example-pdf.png
  Files folder image Files (12)  
File Role Description
Files folder imagefont (4 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file example.pdf Data Auxiliary data
Accessible without login Plain text file example.php Example Example script
Accessible without login Image file example.png Output Example
Plain text file fpdf.php Class Class source
Plain text file PHP2PDFGraphCompare.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (12)  /  font  
File Role Description
  Accessible without login Plain text file helvetica.php Aux. Auxiliary script
  Accessible without login Plain text file helveticab.php Aux. Auxiliary script
  Accessible without login Plain text file helveticabi.php Aux. Auxiliary script
  Accessible without login Plain text file helveticai.php Aux. Auxiliary 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  
 91%
Total:414
This week:0
All time:6,457
This week:35Up
 User Ratings  
 
 All time
Utility:100%StarStarStarStarStarStar
Consistency:100%StarStarStarStarStarStar
Documentation:100%StarStarStarStarStarStar
Examples:100%StarStarStarStarStarStar
Tests:-
Videos:-
Overall:80%StarStarStarStarStar
Rank:17