Subversion Repositories cheapmusic

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
98 - 1
<?php
2
# $Id: data_table.example1.php 999 2011-08-05 19:00:48Z lbayuk $
3
# phplot / contrib / data_table example 1:  Stand-alone data tables
4
# This example does not use PHPlot. Output is a PNG file with multiple
5
# data tables, with varying parameters.
6
require_once 'data_table.php';
7
 
8
$data = array(
9
  array('January',  1,  10, 1e05),
10
  array('February',  2,  20, 1e04),
11
  array('March',  3,  30, 1e03),
12
  array('April',  4,  40, 1e02),
13
  array('May',  5,  '', 1e01),
14
  array('June',  6,  60, 1e00),
15
  array('July',  7,  70,    0),
16
  array('August',  8,  80, 1e-1),
17
  array('September',  9,  90, 1e-2),
18
  array('October', 10, 100, 1e-3),
19
  array('November', 11, 110, 1e-4),
20
  array('December', 12, 120, 1e-5),
21
);
22
 
23
$img_width = 800;
24
$img_height = 600;
25
$cx = $img_width / 2;
26
$cy = $img_height / 2;
27
$tbl_width = $cx - 20;
28
$tbl_height = $cy - 20;
29
 
30
$base_settings = array(
31
    'headers' => array("Label", 'Y1', 'Y2', 'Y3'),
32
    'column_widths' => array(3, 1, 2, 3),
33
    'column_formats' => array('%s', '%d', '%5.2f', '%6g'),
34
    'width' => $tbl_width,
35
    'height' => $tbl_height,
36
    'data' => $data,
37
    'column_alignments' => array('C', 'R', 'R', 'R'),
38
);
39
 
40
$img = imagecreate($img_width, $img_height);
41
$white = imagecolorresolve($img, 255, 255, 255);
42
$red = imagecolorresolve($img, 255, 0, 0);
43
imageline($img, 0, $cy, $img_width-1, $cy, $red);
44
imageline($img, $cx, 0, $cx, $img_height-1, $red);
45
 
46
draw_data_table($img, array_merge($base_settings, array(
47
    'position' => array(10, 10),
48
   )));
49
draw_data_table($img, array_merge($base_settings, array(
50
    'position' => array($cx + 10, 10),
51
    'cellpadding' => 12,
52
    'column_alignments' => array('R', 'L', 'R', 'R'),
53
   )));
54
draw_data_table($img, array_merge($base_settings, array(
55
    'position' => array(10, $cy + 10),
56
    'color' => array(0x66, 0x66, 0xcc),
57
   )));
58
draw_data_table($img, array_merge($base_settings, array(
59
    'position' => array($cx + 10, $cy + 10),
60
    'font' => 4,
61
   )));
62
 
63
imagepng($img);