📄 jpgraph.php
字号:
var $cache_name; // File name to be used for the current graph in the cache directory
var $xgrid=null; // X Grid object (linear or logarithmic)
var $ygrid=null,$y2grid=null, $yngrid=array(); //dito for Y
var $doframe=true,$frame_color=array(0,0,0), $frame_weight=1; // Frame around graph
var $boxed=false, $box_color=array(0,0,0), $box_weight=1; // Box around plot area
var $doshadow=false,$shadow_width=4,$shadow_color=array(102,102,102); // Shadow for graph
var $xaxis=null; // X-axis (instane of Axis class)
var $yaxis=null, $y2axis=null, $ynaxis=array(); // Y axis (instance of Axis class)
var $margin_color=array(200,200,200); // Margin color of graph
var $plotarea_color=array(255,255,255); // Plot area color
var $title,$subtitle,$subsubtitle; // Title and subtitle(s) text object
var $axtype="linlin"; // Type of axis
var $xtick_factor; // Factot to determine the maximum number of ticks depending on the plot with
var $texts=null, $y2texts=null; // Text object to ge shown in the graph
var $lines=null, $y2lines=null;
var $bands=null, $y2bands=null;
var $text_scale_off=0, $text_scale_abscenteroff=-1; // Text scale offset in fractions and for centering bars in absolute pixels
var $background_image="",$background_image_type=-1,$background_image_format="png";
var $background_image_bright=0,$background_image_contr=0,$background_image_sat=0;
var $image_bright=0, $image_contr=0, $image_sat=0;
var $inline;
var $showcsim=0,$csimcolor="red"; //debug stuff, draw the csim boundaris on the image if <>0
var $grid_depth=DEPTH_BACK; // Draw grid under all plots as default
var $iAxisStyle = AXSTYLE_SIMPLE;
var $iCSIMdisplay=false,$iHasStroked = false;
var $footer;
var $csimcachename = '', $csimcachetimeout = 0;
var $iDoClipping = false;
var $y2orderback=true;
var $tabtitle;
var $bkg_gradtype=-1,$bkg_gradstyle=BGRAD_MARGIN;
var $bkg_gradfrom='navy', $bkg_gradto='silver';
var $titlebackground = false;
var $titlebackground_color = 'lightblue',
$titlebackground_style = 1,
$titlebackground_framecolor = 'blue',
$titlebackground_framestyle = 2,
$titlebackground_frameweight = 1,
$titlebackground_bevelheight = 3 ;
var $titlebkg_fillstyle=TITLEBKG_FILLSTYLE_SOLID;
var $titlebkg_scolor1='black',$titlebkg_scolor2='white';
var $framebevel = false, $framebeveldepth = 2 ;
var $framebevelborder = false, $framebevelbordercolor='black';
var $framebevelcolor1='white@0.4', $framebevelcolor2='black@0.4';
var $background_image_mix=100;
var $background_cflag = '';
var $background_cflag_type = BGIMG_FILLPLOT;
var $background_cflag_mix = 100;
var $iImgTrans=false,
$iImgTransHorizon = 100,$iImgTransSkewDist=150,
$iImgTransDirection = 1, $iImgTransMinSize = true,
$iImgTransFillColor='white',$iImgTransHighQ=false,
$iImgTransBorder=false,$iImgTransHorizonPos=0.5;
var $iYAxisDeltaPos=50;
var $iIconDepth=DEPTH_BACK;
//---------------
// CONSTRUCTOR
// aWIdth Width in pixels of image
// aHeight Height in pixels of image
// aCachedName Name for image file in cache directory
// aTimeOut Timeout in minutes for image in cache
// aInline If true the image is streamed back in the call to Stroke()
// If false the image is just created in the cache
function Graph($aWidth=300,$aHeight=200,$aCachedName="",$aTimeOut=0,$aInline=true) {
GLOBAL $gJpgBrandTiming;
// If timing is used create a new timing object
if( $gJpgBrandTiming ) {
global $tim;
$tim = new JpgTimer();
$tim->Push();
}
if( !is_numeric($aWidth) || !is_numeric($aHeight) ) {
JpGraphError::Raise('Image width/height argument in Graph::Graph() must be numeric');
}
// Automatically generate the image file name based on the name of the script that
// generates the graph
if( $aCachedName=="auto" )
$aCachedName=GenImgName();
// Should the image be streamed back to the browser or only to the cache?
$this->inline=$aInline;
$this->img = new RotImage($aWidth,$aHeight);
$this->cache = new ImgStreamCache($this->img);
$this->cache->SetTimeOut($aTimeOut);
$this->title = new Text();
$this->title->ParagraphAlign('center');
$this->title->SetFont(FF_FONT2,FS_BOLD);
$this->title->SetMargin(3);
$this->title->SetAlign('center');
$this->subtitle = new Text();
$this->subtitle->ParagraphAlign('center');
$this->subtitle->SetMargin(2);
$this->subtitle->SetAlign('center');
$this->subsubtitle = new Text();
$this->subsubtitle->ParagraphAlign('center');
$this->subsubtitle->SetMargin(2);
$this->subsubtitle->SetAlign('center');
$this->legend = new Legend();
$this->footer = new Footer();
// Window doesn't like '?' in the file name so replace it with an '_'
$aCachedName = str_replace("?","_",$aCachedName);
// If the cached version exist just read it directly from the
// cache, stream it back to browser and exit
if( $aCachedName!="" && READ_CACHE && $aInline )
if( $this->cache->GetAndStream($aCachedName) ) {
exit();
}
$this->cache_name = $aCachedName;
$this->SetTickDensity(); // Normal density
$this->tabtitle = new GraphTabTitle();
}
//---------------
// PUBLIC METHODS
// Enable final image perspective transformation
function Set3DPerspective($aDir=1,$aHorizon=100,$aSkewDist=120,$aQuality=false,$aFillColor='#FFFFFF',$aBorder=false,$aMinSize=true,$aHorizonPos=0.5) {
$this->iImgTrans = true;
$this->iImgTransHorizon = $aHorizon;
$this->iImgTransSkewDist= $aSkewDist;
$this->iImgTransDirection = $aDir;
$this->iImgTransMinSize = $aMinSize;
$this->iImgTransFillColor=$aFillColor;
$this->iImgTransHighQ=$aQuality;
$this->iImgTransBorder=$aBorder;
$this->iImgTransHorizonPos=$aHorizonPos;
}
// Should the grid be in front or back of the plot?
function SetGridDepth($aDepth) {
$this->grid_depth=$aDepth;
}
function SetIconDepth($aDepth) {
$this->iIconDepth=$aDepth;
}
// Specify graph angle 0-360 degrees.
function SetAngle($aAngle) {
$this->img->SetAngle($aAngle);
}
function SetAlphaBlending($aFlg=true) {
$this->img->SetAlphaBlending($aFlg);
}
// Shortcut to image margin
function SetMargin($lm,$rm,$tm,$bm) {
$this->img->SetMargin($lm,$rm,$tm,$bm);
}
function SetY2OrderBack($aBack=true) {
$this->y2orderback = $aBack;
}
// Rotate the graph 90 degrees and set the margin
// when we have done a 90 degree rotation
function Set90AndMargin($lm=0,$rm=0,$tm=0,$bm=0) {
$lm = $lm ==0 ? floor(0.2 * $this->img->width) : $lm ;
$rm = $rm ==0 ? floor(0.1 * $this->img->width) : $rm ;
$tm = $tm ==0 ? floor(0.2 * $this->img->height) : $tm ;
$bm = $bm ==0 ? floor(0.1 * $this->img->height) : $bm ;
$adj = ($this->img->height - $this->img->width)/2;
$this->img->SetMargin($tm-$adj,$bm-$adj,$rm+$adj,$lm+$adj);
$this->img->SetCenter(floor($this->img->width/2),floor($this->img->height/2));
$this->SetAngle(90);
if( empty($this->yaxis) || empty($this->xaxis) ) {
JpgraphError::Raise('You must specify what scale to use with a call to Graph::SetScale()');
}
$this->xaxis->SetLabelAlign('right','center');
$this->yaxis->SetLabelAlign('center','bottom');
}
function SetClipping($aFlg=true) {
$this->iDoClipping = $aFlg ;
}
// Add a plot object to the graph
function Add(&$aPlot) {
if( $aPlot == null )
JpGraphError::Raise("Graph::Add() You tried to add a null plot to the graph.");
if( is_array($aPlot) && count($aPlot) > 0 )
$cl = strtolower(get_class($aPlot[0]));
else
$cl = strtolower(get_class($aPlot));
if( $cl == 'text' )
$this->AddText($aPlot);
elseif( $cl == 'plotline' )
$this->AddLine($aPlot);
elseif( $cl == 'plotband' )
$this->AddBand($aPlot);
elseif( $cl == 'iconplot' )
$this->AddIcon($aPlot);
else
$this->plots[] = &$aPlot;
}
function AddIcon(&$aIcon) {
if( is_array($aIcon) ) {
for($i=0; $i < count($aIcon); ++$i )
$this->iIcons[]=&$aIcon[$i];
}
else {
$this->iIcons[] = $aIcon ;
}
}
// Add plot to second Y-scale
function AddY2(&$aPlot) {
if( $aPlot == null )
JpGraphError::Raise("Graph::AddY2() You tried to add a null plot to the graph.");
if( is_array($aPlot) && count($aPlot) > 0 )
$cl = strtolower(get_class($aPlot[0]));
else
$cl = strtolower(get_class($aPlot));
if( $cl == 'text' )
$this->AddText($aPlot,true);
elseif( $cl == 'plotline' )
$this->AddLine($aPlot,true);
elseif( $cl == 'plotband' )
$this->AddBand($aPlot,true);
else
$this->y2plots[] = &$aPlot;
}
// Add plot to second Y-scale
function AddY($aN,&$aPlot) {
if( $aPlot == null )
JpGraphError::Raise("Graph::AddYN() You tried to add a null plot to the graph.");
if( is_array($aPlot) && count($aPlot) > 0 )
$cl = strtolower(get_class($aPlot[0]));
else
$cl = strtolower(get_class($aPlot));
if( $cl == 'text' || $cl == 'plotline' || $cl == 'plotband' )
JpGraph::Raise('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::Raise("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::Raise("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::Raise(" 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( $GLOBALS['gd2'] && !USE_TRUECOLOR ) {
JpGraphError::Raise("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::Raise('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::Raise('Unknown file extension ($aImgFormat) in Graph::SetBackgroundImage() for filename: '.$aFileName);
}
}
$this->background_image = $aFileName;
$this->background_image_type=$aBgType;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -