source: temp/trunk/data/class/SC_JpGraph.php @ 1328

Revision 1328, 9.3 KB checked in by naka, 20 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3//¥°¥é¥ÕºîÀ®
4include_once ("jpgraph/jpgraph.php");
5
6class SC_JpGraph {
7
8    var $rgb_table;     // ¿§¤ÎRGB
9    var $rgb_name;      // ¿§¤Î̾Á°
10    var $max_cnt;       // ¥°¥é¥ÕÍ×ÁǤκÇÂç¿ô
11    var $graph_w;       // Éý
12    var $graph_h;       // ¹â¤µ
13    var $margin;        // (array);Çò¤ò¤É¤ì¤À¤±¤È¤ë¤« º¸¡¢±¦¡¢¾å¡¢²¼
14
15    var $objGraph;      // ¥°¥é¥Õ¥ª¥Ö¥¸¥§¥¯¥È
16   
17    function SC_JpGraph($graph_w = 800, $graph_h = 450){
18       
19        $this->max_cnt = 10;                        // ºÇÂçÍ×ÁÇ¿ô¡¡¤³¤ì°Ê¾å¤ÎÃͤòÅϤµ¤ì¤Æ¤â̵»ë¤·¤Þ¤¹
20
21        // ¿§¥Æ¡¼¥Ö¥ë¡ÊÄɲ乤ë¤È¤­¤Ï¥Þ¥Ë¥å¥¢¥ë¤Î¿§¸«Ëܤò¤ß¤Æ²¼¤µ¤¤¡Ë
22        $this->rgb_table = array(   "goldenrod1"
23                                    ,"olivedrab2"
24                                    ,"steelblue2"
25                                    ,"mistyrose"
26                                    ,"azure2"
27                                    ,"navy"
28                                    ,"plum2"
29                                    ,"yellow3"
30                                    ,"lightcoral"
31                                    ,"mediumpurple"
32                                );
33
34        $this->graph_w = $graph_w;
35        $this->graph_h = $graph_h;
36        $this->margin[0] = 40;          // ;Çòº¸ ½é´üÃÍ
37        $this->margin[1] = 30;          // ;Çò±¦ ½é´üÃÍ
38        $this->margin[2] = 30;          // ;Çò¾å ½é´üÃÍ
39        $this->margin[3] = 40;          // ;Çò²¼ ½é´üÃÍ
40    }
41
42    // °ú¿ô$file_path¤¬¤¢¤ì¤Ð¡¢¤½¤Î¾ì½ê¤Ø¥Õ¥¡¥¤¥ë½ÐÎÏ
43    function getGraph($file_path = ""){
44       
45        $this->setMainProperties();
46       
47        if ( $file_path ){
48            // ²èÁü¤ò¥Õ¥¡¥¤¥ë¤Ç½ÐÎϤ¹¤ë
49            $this->objGraph->Stroke( $file_path );
50        } else {
51            //web¥Ú¡¼¥¸ÍѲèÁü½ÐÎÏ
52            $this->objGraph->SetFrame('false', array(255,255,255));
53            $this->objGraph->Stroke();
54        }
55    }
56   
57    function setMainProperties(){
58        //½ÐÎÏÁ°¤Ë¼Â¹Ô¤¹¤ë´Ø¿ô
59        $this->objGraph->legend->SetFont(FF_GOTHIC, FS_NORMAL,8);
60        $this->objGraph->title->SetFont(FF_GOTHIC , FS_NORMAL,12);
61        $this->objGraph->img->SetMargin($this->margin[0],$this->margin[1],$this->margin[2],$this->margin[3]);
62    }
63   
64    function setTitle($title) {
65        $this->objGraph->title->Set($title);
66    }
67   
68    function setWidth($graph_w){
69        // ½ÐÎϲèÁü¤ÎÉý
70        $this->graph_w = $graph_w;
71    }
72   
73    function setHeight($graph_h){                   
74        // ½ÐÎϲèÁü¤Î¹â¤µ
75        $this->graph_h = $graph_h;                 
76    }
77
78    function setMargin($left, $right, $top, $bottom){
79        //¡¡¥°¥é¥Õ¥¨¥ê¥¢¤Î¾å²¼º¸±¦¤Î;ÇòÀßÄê
80        $this->margin[0] = $left;   // ;Çòº¸
81        $this->margin[1] = $right;  // ;Çò±¦
82        $this->margin[2] = $top;    // ;Çò¾å
83        $this->margin[3] = $bottom; // ;Çò²¼
84    }
85}
86
87class SC_JpGraph_Pie extends SC_JpGraph{
88
89    var $graph_size;            // ±ß¤Î¥µ¥¤¥º
90    var $graph_center;
91    var $cnt_min;               // ÃͤκǾ®µ¬½à¿ôÃ͡ʤ³¤ì¤è¤ê¾®¤µ¤¤¤È¡Ö¤½¤Î¾¡×¤Ë¤¤¤ì¤é¤ì¤ë¡Ë
92   
93    function SC_JpGraph_Pie($graph_w = "", $graph_h = "", $graph_size = 100 ){
94        include_once ("jpgraph/jpgraph_pie.php");
95        include_once ("jpgraph/jpgraph_pie3d.php");
96        parent::SC_JpGraph();
97        if ( $graph_w ) $this->setWidth($graph_w);
98        if ( $graph_h ) $this->setHeight($graph_h);
99        $this->objGraph = new PieGraph( $this->graph_w, $this->graph_h, "auto");
100       
101        $this->graph_size = $graph_size;
102        $this->graph_center = 0.35;
103        $this->cnt_min = 1.5;       // ÃͤκǾ®µ¬½à¿ôÃÍ
104    }
105   
106    // setData¤ÎÁ°¤Ë¸Æ¤Ó½Ð¤¹
107    function setPieTitle($title) {
108        $this->title = $title;
109    }
110   
111    function setData($data){
112        // Ï¢ÁÛÇÛÎó¤òÅϤ·¤Þ¤¹ key=ËÞÎã val=ÃÍ¡Êñ°Ì¤Ï%¤òÀ°¿ô¤Çɽ¤·¤¿¿ô¡Ë
113
114        if ( count($data) < $this->max_cnt ) $this->max_cnt = count($data);
115        $i = 0;
116        $otherVal = 0;
117        foreach ( $data as $key=>$val ) {
118            if ( $val <= $this->cnt_min ) {
119                // ºÇ¾®µ¬½à¿ôÃͰʲ¼¤Ï¡Ö¤½¤Î¾¡×¤Ë¤Ê¤ë
120                $otherVal += $val;
121            } else {
122                $arrayHanrei[] = $key."     ";
123                $cnt[] = (double) $val;
124            }
125            $i++;
126            if ($i<$max_cnt) break;
127        }
128        // ºÇ¾®µ¬½à¿ôÃͰʲ¼¤¬¹ç¤Ã¤¿¾ì¹ç¤ÏËöÈø¤Ë¡Ö¤½¤Î¾¡×¤ò¤Ä¤¯¤ë
129        if ( $otherVal > 0 ) {
130            $arrayHanrei[] = "¤½¤Î¾     ";
131            $cnt[] = (double) $otherVal;
132        }
133
134        //ɸ½àÀßÄê¤Ç¤ÏÈ¿»þ·×²ó¤ê¤Î±ß¥°¥é¥Õ¤Ê¤Î¤Ç¡¢µÕ½ç¤Ë¤¹¤ë
135        $p1 = new PiePlot3d( array_reverse($cnt) );     // ±ßÍ×ÁǤòÄɲÃ
136        $p1->SetSliceColors( array_reverse( array_slice($this->rgb_table, 0, $this->max_cnt) ) );
137        $p1->SetStartAngle(90);
138               
139        // ËÞÎã
140        $this->objGraph->legend->SetLayout(LEGEND_VERT);
141        $this->objGraph->legend->Pos(0.013,0.05,"right","top");     // ËÞÎã¤Î°ÌÃÖ
142       
143        // ÆÃÄê¤Îʸ»úÎó¤Ç¥é¥Ù¥ë¤¬Ê¸»ú²½¤±¤¹¤ë¤³¤È¤¬¤¢¤ë¤Î¤ÇÂкö
144        if(is_array($arrayHanrei)) {
145            foreach($arrayHanrei as $key => $val) {
146                // ʸ»ú¥³¡¼¥É¤ÎºÆÊÑ´¹
147                $arrData[$key] = mb_convert_encoding($val, "EUC-JP", "EUC-JP");
148            }
149        }
150       
151        $p1->SetLegends( array_reverse($arrData) );             // ËÞÎã¤âµÕ¸þ¤­¤Ë
152                       
153        $this->objGraph->legend->SetReverse();
154               
155        // ¥°¥é¥Õ¤Î¤½¤Î¾°À­
156        $p1->SetEdge("navy");                   // ¥¨¥Ã¥¸¤Î¿§¡£
157        $p1->value->HideZero();
158        $p1->SetLabelMargin(5);                 // ¥é¥Ù¥ë°ÌÃÖ¡£±ß¤Î¥¨¥Ã¥¸¤«¤é¤Îµ÷Î¥¡£¥Þ¥¤¥Ê¥¹¤ÏÃæ¿´Â¦¤Ë¡£
159        $p1->SetCenter($this->graph_center);
160        $p1->SetSize($this->graph_size);
161        if($this->title != "") {
162            $p1->title->SetFont(FF_GOTHIC, FS_NORMAL,8);
163            $p1->title->SetColor("gray4");
164            $p1->title->Set($this->title);
165            $p1->title->SetMargin(30); 
166        }
167        // Ãͤò¥»¥Ã¥È
168        $this->objGraph->Add($p1);
169    }
170}
171
172class SC_JpGraph_Bar extends SC_JpGraph{
173
174    function SC_JpGraph_Bar ($graph_w = "", $graph_h = ""){
175        include_once ("jpgraph/jpgraph_bar.php");
176        parent::SC_JpGraph();
177        if ( $graph_w ) $this->setWidth($graph_w);
178        if ( $graph_h ) $this->setHeight($graph_h);
179        $this->objGraph = new Graph( $this->graph_w, $this->graph_h, "auto");
180        $this->objGraph->SetScale("textlin");
181        $this->objGraph->SetMarginColor('white');
182        $this->objGraph->yaxis->title->SetFont(FF_GOTHIC, FS_NORMAL,8);     // ½Ä¼´¥é¥Ù¥ë¤Î¥Õ¥©¥ó¥È
183        $this->objGraph->xaxis->title->SetFont(FF_GOTHIC, FS_NORMAL,8);     // ²£¼´¥é¥Ù¥ë¤Î¥Õ¥©¥ó¥È
184        $this->objGraph->xaxis->SetFont(FF_GOTHIC);
185        $this->objGraph->yaxis->SetTitleMargin(35);
186        $this->objGraph->legend->Pos(0.013,0.05,"right","top");             // ËÞÎã¤Î°ÌÃÖ
187    }
188   
189    // ²£¼´¤Î¥¿¥¤¥È¥ë
190    function setXTitle($title) {
191        $this->objGraph->xaxis->SetTitleMargin(10);
192        $this->objGraph->xaxis->title->Set($title);
193        $this->objGraph->xaxis->title->SetColor("gray4");
194    }
195   
196    // ½Ä¼´¤Î¥¿¥¤¥È¥ë
197    function setYTitle($title) {
198        $this->objGraph->subtitle->SetFont(FF_GOTHIC, FS_NORMAL,8);
199        $this->objGraph->subtitle->SetColor("gray4");
200        $this->objGraph->subtitle->Set($title);
201        $this->objGraph->subtitle->SetAlign('left');
202    }
203   
204    function setData($data){
205       
206        if ( count($data) < $this->max_cnt ) $this->max_cnt = count($data); // ºÇÂçÍ×ÁÇ¿ô¤ÎÀßÄê
207        $cnt = 0;
208        $otherVal = 0;
209       
210        foreach ( $data as $key=>$val ) {
211            $arrLabel[] = $key;
212           
213            // ¥°¥é¥ÕËè¤Ë¿§´¹¤¨¤ò¹Ô¤¦¤¿¤á¤ËÇÛÎó¤ò½Å¤Í¤ÆÉÁ²è¤µ¤»¤ë¡£
214            for($i = 0; $i < $this->max_cnt; $i++) {
215                if($cnt == $i) {
216                    $arrVal[$i] = (double)$val;
217                } else {
218                    $arrVal[$i] = 0;
219                }
220            }
221                   
222            $bar[$cnt] = new BarPlot($arrVal);                     
223           
224            //$bar[$i]->SetLegend( $key."     " );      // ÀâÌÀɽ¼¨
225                   
226            $bar[$cnt]->SetFillColor( $this->rgb_table[$cnt] ); // ¿§ÀßÄê
227            $bar[$cnt]->value->Show();
228            $bar[$cnt]->value->SetFont(FF_GOTHIC, FS_NORMAL,8);
229            $bar[$cnt]->value->SetFormat('%01.0f');
230           
231            $bar[$cnt]->SetShadow("black", 1, 1); //±Æ¿§,±Æ¥µ¥¤¥º(h),±Æ¥µ¥¤¥º(y)
232            $bar[$cnt]->SetAlign("center");
233           
234            $bar[$cnt]->SetWidth(0.75);
235           
236            $cnt++;
237            if ($cnt > $this->max_cnt) break;
238        }
239       
240       
241        for($i = 0; $i < $this->max_cnt; $i++) {
242            $this->objGraph->Add($bar[$i]);         
243        }
244           
245        $this->objGraph->xaxis->SetTickLabels($arrLabel);   
246    }   
247}
248
249class SC_JpGraph_Line extends SC_JpGraph{
250   
251    function SC_JpGraph_Line ($graph_w = "", $graph_h = ""){
252        include ("jpgraph/jpgraph_line.php");
253        parent::SC_JpGraph();
254        if ( $graph_w ) $this->setWidth($graph_w);
255        if ( $graph_h ) $this->setHeight($graph_h);
256        $this->objGraph = new Graph( $this->graph_w, $this->graph_h, "auto" );
257        $this->objGraph->SetMarginColor('white');
258        $this->objGraph->SetScale("textlin");
259        $this->objGraph->yaxis->SetTitleMargin(35);                                 // ½Ä¼´ ¸«½Ð¤·¤Þ¤Ç¤Î;Çò
260        $this->objGraph->yaxis->title->SetFont(FF_GOTHIC, FS_NORMAL,8);             // ½Ä¼´ ¸«½Ð¤·¤Î¥Õ¥©¥ó¥È
261        $this->objGraph->xaxis->title->SetFont(FF_GOTHIC, FS_NORMAL,8);             // ²£¼´ ¸«½Ð¤·¤Î¥Õ¥©¥ó¥È
262        $this->objGraph->xaxis->SetFont(FF_GOTHIC);                                 // ²£¼´ ÃͤΥե©¥ó¥È
263    }
264   
265    // ²£¼´¥é¥Ù¥ë¤ò²¿¸Ä¤Ë°ì²óɽ¼¨¤µ¤»¤ë¤«
266    function setXLabelInterval($interval) {
267        $this->objGraph->xaxis->SetTextLabelInterval($interval);                   
268    }
269   
270    // ²£¼´¥é¥Ù¥ë¤Îɽ¼¨³ÑÅÙ¡ÊÆüËܸìÉԲġË
271    function setXLabelAngle($angle) {
272        $this->objGraph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
273        $this->objGraph->xaxis->SetLabelAngle($angle);
274    }
275   
276    // ²£¼´¤Î¥¿¥¤¥È¥ë
277    function setXTitle($title) {
278        $this->objGraph->xaxis->SetTitleMargin(25);
279        $this->objGraph->xaxis->title->Set($title);
280        $this->objGraph->xaxis->title->SetColor("gray4");
281    }
282   
283    // ½Ä¼´¤Î¥¿¥¤¥È¥ë
284    function setYTitle($title) {
285        $this->objGraph->subtitle->SetFont(FF_GOTHIC, FS_NORMAL,8);
286        $this->objGraph->subtitle->SetColor("gray4");
287        $this->objGraph->subtitle->Set($title);
288        $this->objGraph->subtitle->SetAlign('left');
289    }
290   
291    // ²£¼´¥é¥Ù¥ë¤Îɽ¼¨¥¿¥¤¥×¡ÊÆüËܸìÉԲġË
292    function setXLabelBold($ttf, $type) {
293        $this->objGraph->xaxis->SetFont($ttf, $type, 8);
294    }
295   
296    function setData($data){
297
298        if ( count($data) < $this->max_cnt ) $this->max_cnt = count($data); //ºÇÂçÍ×ÁÇ¿ô¤ÎÀßÄê
299       
300        $i =0;
301        foreach ( $data as $key=>$val ) {
302            $arrayHanrei[] = $key;
303            $cnt[] = (double) $val;
304            $i++;
305            if ($i < $max_cnt) break;
306        }
307        $bar = new linePlot( $cnt );
308        $bar->value->Show();
309        $bar->value->SetFont(FF_GOTHIC, FS_NORMAL,8);           // ÃͤΥե©¥ó¥È
310        $bar->value->SetFormat('%01.0f');
311        $bar->SetStyle('solid');
312        $bar->SetColor("navy");                                 // Àþ¤Î¿§
313        $bar->SetCenter();
314        $bar->mark->SetType(MARK_FILLEDCIRCLE);                 // ¥Ý¥¤¥ó¥È¤Î·Á
315        $bar->mark->SetFillColor("red");                        // ¥Ý¥¤¥ó¥È¤Î¿§
316        $bar->mark->SetWidth(2);                                // ¥Ý¥¤¥ó¥È¤Î¥µ¥¤¥º
317       
318        $this->objGraph->Add($bar);     
319        $this->objGraph->xaxis->SetTickLabels($arrayHanrei);
320    }
321   
322}
323?>
Note: See TracBrowser for help on using the repository browser.