1 | <?php // content="text/plain; charset=utf-8" |
---|
2 | require_once('jpgraph/jpgraph.php'); |
---|
3 | require_once('jpgraph/jpgraph_matrix.php'); |
---|
4 | require_once('jpgraph/jpgraph_plotline.php'); |
---|
5 | |
---|
6 | |
---|
7 | $data = array( |
---|
8 | array(0,null,2,3,4,5,6,7,8,9,10,8,6,4,2), |
---|
9 | array(10,9,8,7,6,5,4,3,2,1,0,8,5,9,2), |
---|
10 | array(0,1,2,3,4,5,6,7,8,9,10,2,4,5,7), |
---|
11 | array(10,9,8,17,6,5,4,3,2,1,0,8,6,4,2), |
---|
12 | array(0,1,2,3,4,4,9,7,8,9,10,3,2,7,2), |
---|
13 | array(8,1,2,3,4,8,3,7,8,9,10,5,3,9,1), |
---|
14 | array(10,3,5,7,6,5,4,3,12,1,0,6,5,10,2), |
---|
15 | array(10,9,8,7,6,5,4,3,2,1,NULL,8,6,4,2), |
---|
16 | ); |
---|
17 | |
---|
18 | $nx = count($data[0]); |
---|
19 | $ny = count($data); |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | for($i=0; $i < $nx; ++$i ) { |
---|
24 | $collabels[$i] = sprintf('column label: %02d',$i); |
---|
25 | |
---|
26 | } |
---|
27 | for($i=0; $i < $ny; ++$i ) { |
---|
28 | $rowlabels[$i] = sprintf('row label: %02d',$i); |
---|
29 | } |
---|
30 | |
---|
31 | // Setup a nasic matrix graph |
---|
32 | $graph = new MatrixGraph(400,350); |
---|
33 | |
---|
34 | $graph->SetBackgroundGradient('lightsteelblue:0.8','lightsteelblue:0.3'); |
---|
35 | $graph->title->Set('Matrix with lines'); |
---|
36 | $graph->title->SetFont(FF_ARIAL,FS_BOLD,18); |
---|
37 | $graph->title->SetColor('white'); |
---|
38 | |
---|
39 | // Create two lines to add as markers |
---|
40 | $l1 = new PlotLine(VERTICAL, 5, 'lightgray:1.5', 4); |
---|
41 | $l2 = new PlotLine(HORIZONTAL, 3, 'lightgray:1.5', 4); |
---|
42 | |
---|
43 | // Create one matrix plot |
---|
44 | $mp = new MatrixPlot($data,1); |
---|
45 | $mp->SetModuleSize(13,15); |
---|
46 | $mp->SetCenterPos(0.35,0.6); |
---|
47 | $mp->colormap->SetNullColor('gray'); |
---|
48 | |
---|
49 | // Add lines |
---|
50 | $mp->AddLine($l1); |
---|
51 | $mp->AddLine($l2); |
---|
52 | // this could also be done as |
---|
53 | // $mp->AddLine(array($l1,$l2)); |
---|
54 | |
---|
55 | // Setup column lablels |
---|
56 | $mp->collabel->Set($collabels); |
---|
57 | $mp->collabel->SetSide('top'); |
---|
58 | $mp->collabel->SetFont(FF_ARIAL,FS_NORMAL,8); |
---|
59 | $mp->collabel->SetFontColor('lightgray'); |
---|
60 | |
---|
61 | // Setup row lablels |
---|
62 | $mp->rowlabel->Set($rowlabels); |
---|
63 | $mp->rowlabel->SetSide('right'); |
---|
64 | $mp->rowlabel->SetFont(FF_ARIAL,FS_NORMAL,8); |
---|
65 | $mp->rowlabel->SetFontColor('lightgray'); |
---|
66 | |
---|
67 | // Move the legend more to the right |
---|
68 | $mp->legend->SetMargin(90); |
---|
69 | $mp->legend->SetColor('white'); |
---|
70 | $mp->legend->SetFont(FF_VERDANA,FS_BOLD,10); |
---|
71 | |
---|
72 | $graph->Add($mp); |
---|
73 | $graph->Stroke(); |
---|
74 | |
---|
75 | ?> |
---|