[PHP-users 2626] Re: JpGraphを使ってらっしゃる方いますか?
Nakagawa, Yasuharu
php-users@php.gr.jp
Wed, 10 Oct 2001 18:17:09 +0900
中川@東京武蔵野市です。
In message 田中 雅英 wrote...
>Message-ID: <3BC3D572.6626B55E@nddhq.co.jp>
>From: 田中 雅英 <m-tanaka@nddhq.co.jp>
>Date: Wed, 10 Oct 2001 13:58:27 +0900
>Subject: [PHP-users 2618] JpGraphを使ってらっしゃる方いますか?
>
>そこで「GD」などを調べてみたら「JpGraph」というGDを利用したクラスライブ
>ラリを見つけました。
JpGraphは PHP4用ですよね。
表示がかっこいいので、使って見たいと思っています。
うちの環境はPHP3なので、類似のPHPlot-4.4.6を使っています。
こちらは、そのままでもPHP3で描画できたと思います。
なお、積上げバーグラフを描きたかったので、下記のようにちょっと手を加えていますが。。
------------始まり
diff -cwr phplot-4.4.6/phplot.php.orig phplot-4.4.6/phplot.php
*** phplot-4.4.6/phplot.php.orig Tue Mar 27 00:52:02 2001
--- phplot-4.4.6/phplot.php Tue Jul 10 14:07:38 2001
***************
*** 779,785 ****
}
function SetPlotType($which_pt) {
! $accepted = "bars,lines,linepoints,area,points,pie,thinbarline";
$asked = trim($which_pt);
if (eregi($asked, $accepted)) {
$this->plot_type = $which_pt;
--- 779,785 ----
}
function SetPlotType($which_pt) {
! $accepted = "accbars,bars,lines,linepoints,area,points,pie,thinbarline";
$asked = trim($which_pt);
if (eregi($asked, $accepted)) {
$this->plot_type = $which_pt;
***************
*** 829,850 ****
$tmp = 0;
$total_records += count($dat) - 1; // -1 for label
switch ($this->data_type) {
case "text-data":
//Find the relative Max and Min
!
while (list($key, $val) = each($dat)) {
if ($key != 0) { //$dat[0] = label
SetType($val,"double");
if ($val > $maxy) {
! $maxy = $val ;
}
if ($val < $miny) {
! $miny = (double) $val ;
}
}
$tmp++;
}
break;
case "data-data": //X-Y data is passed in as $data[] = (title,x,y,y2,y3,...) which you can use for multi-dimentional plots.
--- 829,861 ----
$tmp = 0;
$total_records += count($dat) - 1; // -1 for label
+
switch ($this->data_type) {
case "text-data":
//Find the relative Max and Min
! $maxy0 = $maxy ;
! $miny0 = $miny ;
while (list($key, $val) = each($dat)) {
if ($key != 0) { //$dat[0] = label
SetType($val,"double");
+ if ( $this->plot_type == "accbars" ) {
+ $maxy0 += (double)$val ;
+ if ( $val < 0 ) {
+ $miny0 += $val ;
+ }
+ } else {
if ($val > $maxy) {
! $maxy0 = $val ;
}
if ($val < $miny) {
! $miny0 = (double) $val ;
! }
}
}
$tmp++;
}
+ $maxy = ( $maxy > $maxy0 )? $maxy : $maxy0 ;
+ $miny = ( $miny < $miny0 )? $miny : $miny0 ;
break;
case "data-data": //X-Y data is passed in as $data[] = (title,x,y,y2,y3,...) which you can use for multi-dimentional plots.
***************
*** 2436,2441 ****
--- 2447,2526 ----
}
} //function DrawBars
+ function DrawAccBars() {
+ if ($this->data_type != "text-data") {
+ $this->DrawError('Bar plots must be text-data: use function SetDataType("text-data")');
+ }
+
+ $xadjust = ($this->records_per_group * $this->record_bar_width )/4;
+
+ reset($this->data_values);
+ while (list($j, $row) = each($this->data_values)) {
+
+ $color_index = 0;
+ $colbarcount = 0;
+ $x_now = $this->xtr($j+.5);
+
+ $ya = $yi = 0 ;
+ $y0 = $this->x_axis_position;
+
+ while (list($k, $v) = each($row)) {
+ if ($k == 0) {
+ //Draw Data Labels
+ $xlab = SubStr($v,0,$this->x_datalabel_maxlength);
+ $this->DrawXDataLabel($xlab,$x_now);
+ } else {
+ // Draw Bars ($v)
+ $x1 = $x_now - $this->data_group_space ;
+ $x2 = $x1 + $this->record_bar_width*$this->records_per_group;
+
+ // if ($v < $this->x_axis_position) {
+ // $y1 = $this->ytr($this->x_axis_position);
+ // $y2 = $this->ytr($v);
+ // } else {
+ // $y1 = $this->ytr($v);
+ // $y2 = $this->ytr($this->x_axis_position);
+ // }
+ if ($v < $this->x_axis_position) {
+ $y1 = $this->ytr($ya + $y0);
+ $y2 = $this->ytr($ya + $v);
+ $ya = $ya + $v;
+ } else {
+ $y1 = $this->ytr($yi + $v);
+ $y2 = $this->ytr($yi + $y0);
+ $yi = $yi + $v ;
+ }
+
+ if ($color_index >= count($this->ndx_data_color)) $color_index=0;
+ if ($colbarcount >= count($this->ndx_data_border_color)) $colbarcount=0;
+ $barcol = $this->ndx_data_color[$color_index];
+ $bordercol = $this->ndx_data_border_color[$colbarcount];
+
+ if ((strval($v) != "") ) { //Allow for missing Y data
+ if ($this->shading > 0) {
+ for($i=0;$i<($this->shading);$i++) {
+ //Shading set in SetDefaultColors
+ ImageFilledRectangle($this->img, $x1+$i, $y1-$i, $x2+$i, $y2-$i, $this->ndx_i_light);
+ }
+ }
+
+ ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $barcol);
+ ImageRectangle($this->img, $x1, $y1, $x2, $y2, $bordercol);
+ if ($this->draw_data_labels == '1') { //ajo
+ $y1 = $this->ytr($this->label_scale_position * $v);
+ //$this->DrawDataLabel($v,$j + .5,$v*$this->label_scale_position);
+ $this->DrawText($this->x_label_ttffont, $this->x_label_angle,
+ $x1+$this->record_bar_width/2, $y1, $this->ndx_label_color, $this->x_label_ttffont_size, $v,'center','top');
+ }
+ }
+
+ $color_index++;
+ $colbarcount++;
+ }
+ }
+ }
+ } //function DrawAccBars
+
function DrawLegend($which_x1,$which_y1,$which_boxtype) {
//Base code submitted by Marlin Viss
$max_legend_length=0;
***************
*** 2461,2467 ****
}
//Lower Right
! $box_end_y = $box_start_y + $this->small_font_height*(count($this->legend)+1) + 2*$vert_margin;
//$box_end_x = $this->plot_area[2] - 5;
$box_end_x = $box_start_x + $this->small_font_width*($max_legend_length+4) - 5;
--- 2546,2552 ----
}
//Lower Right
! $box_end_y = $box_start_y + $this->small_font_height*(count($this->legend)+3) + 2*$vert_margin;
//$box_end_x = $this->plot_area[2] - 5;
$box_end_x = $box_start_x + $this->small_font_width*($max_legend_length+4) - 5;
***************
*** 2555,2560 ****
--- 2640,2651 ----
//ImageString($this->img, 4, 20, 20, $foo, $this->ndx_text_color);
switch ($this->plot_type) {
+ case "accbars":
+ $this->DrawPlotBorder();
+ $this->DrawLabels();
+ $this->DrawAccBars();
+ $this->DrawXAxis();
+ break;
case "bars":
$this->DrawPlotBorder();
$this->DrawLabels();
------------終わり
以上
--
Nakagawa, Yasuharu <yasuharu_nakagawa@yokogawa.co.jp>
中川 康晴 @ 横河電機(株)コンポ事業部室 (PHS:25842)
Key fingerprint = 4ABF 08D3 BF9B 1CC5 AB0C A30F 6427 1ADB 5C8D 4F14