jpgraph.php
来自「通达OA2007SE源代码 非常好的」· PHP 代码 · 共 2,039 行 · 第 1/5 页
PHP
2,039 行
} // Add plot to second Y-scale function AddY2($aPlot) { if( $aPlot == null ) JpGraphError::RaiseL(25011);//("Graph::AddY2() You tried to add a null plot to the graph."); if( is_array($aPlot) && count($aPlot) > 0 ) $cl = $aPlot[0]; else $cl = $aPlot; if( $cl instanceof Text ) $this->AddText($aPlot,true); elseif( $cl instanceof PlotLine ) $this->AddLine($aPlot,true); elseif( class_exists('PlotBand',false) && ($cl instanceof PlotBand) ) $this->AddBand($aPlot,true); else $this->y2plots[] = $aPlot; } // Add plot to the extra Y-axises function AddY($aN,$aPlot) { if( $aPlot == null ) JpGraphError::RaiseL(25012);//("Graph::AddYN() You tried to add a null plot to the graph."); if( is_array($aPlot) && count($aPlot) > 0 ) $cl = $aPlot[0]; else $cl = $aPlot; if( ($cl instanceof Text) || ($cl instanceof PlotLine) || (class_exists('PlotBand',false) && ($cl instanceof PlotBand)) ) JpGraph::RaiseL(25013);//('You can only add standard plots to multiple Y-axis'); else $this->ynplots[$aN][] = $aPlot; } // Add text object to the graph function AddText($aTxt,$aToY2=false) { if( $aTxt == null ) JpGraphError::RaiseL(25014);//("Graph::AddText() You tried to add a null text to the graph."); if( $aToY2 ) { if( is_array($aTxt) ) { for($i=0; $i < count($aTxt); ++$i ) $this->y2texts[]=$aTxt[$i]; } else $this->y2texts[] = $aTxt; } else { if( is_array($aTxt) ) { for($i=0; $i < count($aTxt); ++$i ) $this->texts[]=$aTxt[$i]; } else $this->texts[] = $aTxt; } } // Add a line object (class PlotLine) to the graph function AddLine($aLine,$aToY2=false) { if( $aLine == null ) JpGraphError::RaiseL(25015);//("Graph::AddLine() You tried to add a null line to the graph."); if( $aToY2 ) { if( is_array($aLine) ) { for($i=0; $i < count($aLine); ++$i ) $this->y2lines[]=$aLine[$i]; } else $this->y2lines[] = $aLine; } else { if( is_array($aLine) ) { for($i=0; $i<count($aLine); ++$i ) $this->lines[]=$aLine[$i]; } else $this->lines[] = $aLine; } } // Add vertical or horizontal band function AddBand($aBand,$aToY2=false) { if( $aBand == null ) JpGraphError::RaiseL(25016);//(" Graph::AddBand() You tried to add a null band to the graph."); if( $aToY2 ) { if( is_array($aBand) ) { for($i=0; $i < count($aBand); ++$i ) $this->y2bands[] = $aBand[$i]; } else $this->y2bands[] = $aBand; } else { if( is_array($aBand) ) { for($i=0; $i < count($aBand); ++$i ) $this->bands[] = $aBand[$i]; } else $this->bands[] = $aBand; } } function SetBackgroundGradient($aFrom='navy',$aTo='silver',$aGradType=2,$aStyle=BGRAD_FRAME) { $this->bkg_gradtype=$aGradType; $this->bkg_gradstyle=$aStyle; $this->bkg_gradfrom = $aFrom; $this->bkg_gradto = $aTo; } // Set a country flag in the background function SetBackgroundCFlag($aName,$aBgType=BGIMG_FILLPLOT,$aMix=100) { $this->background_cflag = $aName; $this->background_cflag_type = $aBgType; $this->background_cflag_mix = $aMix; } // Alias for the above method function SetBackgroundCountryFlag($aName,$aBgType=BGIMG_FILLPLOT,$aMix=100) { $this->background_cflag = $aName; $this->background_cflag_type = $aBgType; $this->background_cflag_mix = $aMix; } // Specify a background image function SetBackgroundImage($aFileName,$aBgType=BGIMG_FILLPLOT,$aImgFormat="auto") { if( !USE_TRUECOLOR ) { JpGraphError::RaiseL(25017);//("You are using GD 2.x and are trying to use a background images on a non truecolor image. To use background images with GD 2.x you <b>must</b> enable truecolor by setting the USE_TRUECOLOR constant to TRUE. Due to a bug in GD 2.0.1 using any truetype fonts with truecolor images will result in very poor quality fonts."); } // Get extension to determine image type if( $aImgFormat == "auto" ) { $e = explode('.',$aFileName); if( !$e ) { JpGraphError::RaiseL(25018,$aFileName);//('Incorrect file name for Graph::SetBackgroundImage() : '.$aFileName.' Must have a valid image extension (jpg,gif,png) when using autodetection of image type'); } $valid_formats = array('png', 'jpg', 'gif'); $aImgFormat = strtolower($e[count($e)-1]); if ($aImgFormat == 'jpeg') { $aImgFormat = 'jpg'; } elseif (!in_array($aImgFormat, $valid_formats) ) { JpGraphError::RaiseL(25019,$aImgFormat);//('Unknown file extension ($aImgFormat) in Graph::SetBackgroundImage() for filename: '.$aFileName); } } $this->background_image = $aFileName; $this->background_image_type=$aBgType; $this->background_image_format=$aImgFormat; } function SetBackgroundImageMix($aMix) { $this->background_image_mix = $aMix ; } // Adjust brightness and constrast for background image function AdjBackgroundImage($aBright,$aContr=0,$aSat=0) { $this->background_image_bright=$aBright; $this->background_image_contr=$aContr; $this->background_image_sat=$aSat; } // Adjust brightness and constrast for image function AdjImage($aBright,$aContr=0,$aSat=0) { $this->image_bright=$aBright; $this->image_contr=$aContr; $this->image_sat=$aSat; } // Specify axis style (boxed or single) function SetAxisStyle($aStyle) { $this->iAxisStyle = $aStyle ; } // Set a frame around the plot area function SetBox($aDrawPlotFrame=true,$aPlotFrameColor=array(0,0,0),$aPlotFrameWeight=1) { $this->boxed = $aDrawPlotFrame; $this->box_weight = $aPlotFrameWeight; $this->box_color = $aPlotFrameColor; } // Specify color for the plotarea (not the margins) function SetColor($aColor) { $this->plotarea_color=$aColor; } // Specify color for the margins (all areas outside the plotarea) function SetMarginColor($aColor) { $this->margin_color=$aColor; } // Set a frame around the entire image function SetFrame($aDrawImgFrame=true,$aImgFrameColor=array(0,0,0),$aImgFrameWeight=1) { $this->doframe = $aDrawImgFrame; $this->frame_color = $aImgFrameColor; $this->frame_weight = $aImgFrameWeight; } function SetFrameBevel($aDepth=3,$aBorder=false,$aBorderColor='black',$aColor1='white@0.4',$aColor2='darkgray@0.4',$aFlg=true) { $this->framebevel = $aFlg ; $this->framebeveldepth = $aDepth ; $this->framebevelborder = $aBorder ; $this->framebevelbordercolor = $aBorderColor ; $this->framebevelcolor1 = $aColor1 ; $this->framebevelcolor2 = $aColor2 ; $this->doshadow = false ; } // Set the shadow around the whole image function SetShadow($aShowShadow=true,$aShadowWidth=5,$aShadowColor=array(102,102,102)) { $this->doshadow = $aShowShadow; $this->shadow_color = $aShadowColor; $this->shadow_width = $aShadowWidth; $this->footer->iBottomMargin += $aShadowWidth; $this->footer->iRightMargin += $aShadowWidth; } // Specify x,y scale. Note that if you manually specify the scale // you must also specify the tick distance with a call to Ticks::Set() function SetScale($aAxisType,$aYMin=1,$aYMax=1,$aXMin=1,$aXMax=1) { $this->axtype = $aAxisType; if( $aYMax < $aYMin || $aXMax < $aXMin ) JpGraphError::RaiseL(25020);//('Graph::SetScale(): Specified Max value must be larger than the specified Min value.'); $yt=substr($aAxisType,-3,3); if( $yt=="lin" ) $this->yscale = new LinearScale($aYMin,$aYMax); elseif( $yt == "int" ) { $this->yscale = new LinearScale($aYMin,$aYMax); $this->yscale->SetIntScale(); } elseif( $yt=="log" ) $this->yscale = new LogScale($aYMin,$aYMax); else JpGraphError::RaiseL(25021,$aAxisType);//("Unknown scale specification for Y-scale. ($aAxisType)"); $xt=substr($aAxisType,0,3); if( $xt == "lin" || $xt == "tex" ) { $this->xscale = new LinearScale($aXMin,$aXMax,"x"); $this->xscale->textscale = ($xt == "tex"); } elseif( $xt == "int" ) { $this->xscale = new LinearScale($aXMin,$aXMax,"x"); $this->xscale->SetIntScale(); } elseif( $xt == "dat" ) { $this->xscale = new DateScale($aXMin,$aXMax,"x"); } elseif( $xt == "log" ) $this->xscale = new LogScale($aXMin,$aXMax,"x"); else JpGraphError::RaiseL(25022,$aAxisType);//(" Unknown scale specification for X-scale. ($aAxisType)"); $this->xaxis = new Axis($this->img,$this->xscale); $this->yaxis = new Axis($this->img,$this->yscale); $this->xgrid = new Grid($this->xaxis); $this->ygrid = new Grid($this->yaxis); $this->ygrid->Show(); } // Specify secondary Y scale function SetY2Scale($aAxisType="lin",$aY2Min=1,$aY2Max=1) { if( $aAxisType=="lin" ) $this->y2scale = new LinearScale($aY2Min,$aY2Max); elseif( $aAxisType == "int" ) { $this->y2scale = new LinearScale($aY2Min,$aY2Max); $this->y2scale->SetIntScale(); } elseif( $aAxisType=="log" ) { $this->y2scale = new LogScale($aY2Min,$aY2Max); } else JpGraphError::RaiseL(25023,$aAxisType);//("JpGraph: Unsupported Y2 axis type: $aAxisType\nMust be one of (lin,log,int)"); $this->y2axis = new Axis($this->img,$this->y2scale); $this->y2axis->scale->ticks->SetDirection(SIDE_LEFT); $this->y2axis->SetLabelSide(SIDE_RIGHT); $this->y2axis->SetPos('max'); $this->y2axis->SetTitleSide(SIDE_RIGHT); // Deafult position is the max x-value $this->y2grid = new Grid($this->y2axis); } // Set the delta position (in pixels) between the multiple Y-axis function SetYDeltaDist($aDist) { $this->iYAxisDeltaPos = $aDist; } // Specify secondary Y scale function SetYScale($aN,$aAxisType="lin",$aYMin=1,$aYMax=1) { if( $aAxisType=="lin" ) $this->ynscale[$aN] = new LinearScale($aYMin,$aYMax); elseif( $aAxisType == "int" ) { $this->ynscale[$aN] = new LinearScale($aYMin,$aYMax); $this->ynscale[$aN]->SetIntScale(); } elseif( $aAxisType=="log" ) { $this->ynscale[$aN] = new LogScale($aYMin,$aYMax); } else JpGraphError::RaiseL(25024,$aAxisType);//("JpGraph: Unsupported Y axis type: $aAxisType\nMust be one of (lin,log,int)"); $this->ynaxis[$aN] = new Axis($this->img,$this->ynscale[$aN]); $this->ynaxis[$aN]->scale->ticks->SetDirection(SIDE_LEFT); $this->ynaxis[$aN]->SetLabelSide(SIDE_RIGHT); } // Specify density of ticks when autoscaling 'normal', 'dense', 'sparse', 'verysparse' // The dividing factor have been determined heuristically according to my aesthetic // sense (or lack off) y.m.m.v ! function SetTickDensity($aYDensity=TICKD_NORMAL,$aXDensity=TICKD_NORMAL) { $this->xtick_factor=30; $this->ytick_factor=25; switch( $aYDensity ) { case TICKD_DENSE: $this->ytick_factor=12; break; case TICKD_NORMAL: $this->ytick_factor=25; break; case TICKD_SPARSE: $this->ytick_factor=40; break; case TICKD_VERYSPARSE: $this->ytick_factor=100; break; default: JpGraphError::RaiseL(25025,$densy);//("JpGraph: Unsupported Tick density: $densy"); } switch( $aXDensity ) { case TICKD_DENSE: $this->xtick_factor=15; break; case TICKD_NORMAL: $this->xtick_factor=30; break; case TICKD_SPARSE: $this->xtick_factor=45; break; case TICKD_VERYSPARSE: $this->xtick_factor=60; break; default: JpGraphError::RaiseL(25025,$densx);//("JpGraph: Unsupported Tick density: $densx"); } } // Get a string of all image map areas function GetCSIMareas() { if( !$this->iHasStroked ) $this->Stroke(_CSIM_SPECIALFILE); $csim = $this->title->GetCSIMAreas(); $csim .= $this->subtitle->GetCSIMAreas(); $csim .= $this->subsubtitle->GetCSIMAreas(); $csim .= $this->legend->GetCSIMAreas(); if( $this->y2axis != NULL ) { $csim .= $this->y2axis->title->GetCSIMAreas(); } if( $this->texts != null ) { $n = count($this->texts); for($i=0; $i < $n; ++$i ) { $csim .= $this->texts[$i]->GetCSIMAreas(); } } if( $this->y2texts != null && $this->y2scale != null ) { $n = count($this->y2texts); for($i=0; $i < $n; ++$i ) { $csim .= $this->y2texts[$i]->GetCSIMAreas(); } } if( $this->yaxis != null && $this->xaxis != null ) { $csim .= $this->yaxis->title->GetCSIMAreas(); $csim .= $this->xaxis->title->GetCSIMAreas(); } $n = count($this->plots); for( $i=0; $i < $n; ++$i ) $csim .= $this->plots[$i]->GetCSIMareas(); $n = count($this->y2plots); for( $i=0; $i < $n; ++$i ) $csim .= $this->y2plots[$i]->GetCSIMareas(); $n = count($this->ynaxis); for( $i=0; $i < $n; ++$i ) { $m = count($this->ynplots[$i]); for($j=0; $j < $m; ++$j ) { $csim .= $this->ynplots[$i][$j]->GetCSIMareas(); } } $n = count($this->iTables);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?