📄 jpgraph.php
字号:
'AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACx'. 'IAAAsSAdLdfvwAAAAHdElNRQfTBgISOCqusfs5AAABLUlEQVR4'. '2tWV3XKCMBBGWfkranCIVClKLd/7P2Q3QsgCxjDTq+6FE2cPH+'. 'xJ0Ogn2lQbsT+Wrs+buAZAV4W5T6Bs0YXBBwpKgEuIu+JERAX6'. 'wM2rHjmDdEITmsQEEmWADgZm6rAjhXsoMGY9B/NZBwJzBvn+e3'. 'wHntCAJdGu9SviwIwoZVDxPB9+Rc0TSEbQr0j3SA1gwdSn6Db0'. '6Tm1KfV6yzWGQO7zdpvyKLKBDmRFjzeB3LYgK7r6A/noDAfjtS'. 'IXaIzbJSv6WgUebTMV4EoRB8a2mQiQjgtF91HdKDKZ1gtFtQjk'. 'YcWaR5OKOhkYt+ZsTFdJRfPAApOpQYJTNHvCRSJR6SJngQadfc'. 'vd69OLMddVOPCGVnmrFD8bVYd3JXfxXPtLR/+mtv59/ALWiiMx'. 'qL72fwAAAABJRU5ErkJggg==' ; if( function_exists("imagetypes") ) $supported = imagetypes(); else $supported = 0; if( !function_exists('imagecreatefromstring') ) $supported = 0; if( ob_get_length() || headers_sent() || !($supported & IMG_PNG) ) { // Special case for headers already sent or that the installation doesn't support // the PNG format (which the error icon is encoded in). // Dont return an image since it can't be displayed die($this->iTitle.' '.$aMsg); } $aMsg = wordwrap($aMsg,55); $lines = substr_count($aMsg,"\n"); // Create the error icon GD $erricon = Image::CreateFromString(base64_decode($img_iconerror)); // Create an image that contains the error text. $w=400; $h=100 + 15*max(0,$lines-3); $img = new Image($w,$h); // Drop shadow $img->SetColor("gray"); $img->FilledRectangle(5,5,$w-1,$h-1,10); $img->SetColor("gray:0.7"); $img->FilledRectangle(5,5,$w-3,$h-3,10); // Window background $img->SetColor("lightblue"); $img->FilledRectangle(1,1,$w-5,$h-5); $img->CopyCanvasH($img->img,$erricon,5,30,0,0,40,40); // Window border $img->SetColor("black"); $img->Rectangle(1,1,$w-5,$h-5); $img->Rectangle(0,0,$w-4,$h-4); // Window top row $img->SetColor("darkred"); for($y=3; $y < 18; $y += 2 ) $img->Line(1,$y,$w-6,$y); // "White shadow" $img->SetColor("white"); // Left window edge $img->Line(2,2,2,$h-5); $img->Line(2,2,$w-6,2); // "Gray button shadow" $img->SetColor("darkgray"); // Gray window shadow $img->Line(2,$h-6,$w-5,$h-6); $img->Line(3,$h-7,$w-5,$h-7); // Window title $m = floor($w/2-5); $l = 100; $img->SetColor("lightgray:1.3"); $img->FilledRectangle($m-$l,2,$m+$l,16); // Stroke text $img->SetColor("darkred"); $img->SetFont(FF_FONT2,FS_BOLD); $img->StrokeText($m-50,15,$this->iTitle); $img->SetColor("black"); $img->SetFont(FF_FONT1,FS_NORMAL); $txt = new Text($aMsg,52,25); $txt->Align("left","top"); $txt->Stroke($img); if ($this->iDest) { $img->Stream($this->iDest); } else { $img->Headers(); $img->Stream(); } if( $aHalt ) die(); }}//// Setup PHP error handler//function _phpErrorHandler($errno,$errmsg,$filename, $linenum, $vars) { // Respect current error level if( $errno & error_reporting() ) { JpGraphError::RaiseL(25003,basename($filename),$linenum,$errmsg); }}if( INSTALL_PHP_ERR_HANDLER ) { set_error_handler("_phpErrorHandler");}////Check if there were any warnings, perhaps some wrong includes by the user//if( isset($GLOBALS['php_errormsg']) && CATCH_PHPERRMSG && !preg_match('|Deprecated|', $GLOBALS['php_errormsg'])) { JpGraphError::RaiseL(25004,$GLOBALS['php_errormsg']);}// Useful mathematical functionfunction sign($a) {return $a >= 0 ? 1 : -1;}// Utility function to generate an image name based on the filename we// are running from and assuming we use auto detection of graphic format// (top level), i.e it is safe to call this function// from a script that uses JpGraphfunction GenImgName() { global $_SERVER; // Determine what format we should use when we save the images $supported = imagetypes(); if( $supported & IMG_PNG ) $img_format="png"; elseif( $supported & IMG_GIF ) $img_format="gif"; elseif( $supported & IMG_JPG ) $img_format="jpeg"; if( !isset($_SERVER['PHP_SELF']) ) JpGraphError::RaiseL(25005);//(" Can't access PHP_SELF, PHP global variable. You can't run PHP from command line if you want to use the 'auto' naming of cache or image files."); $fname = basename($_SERVER['PHP_SELF']); if( !empty($_SERVER['QUERY_STRING']) ) { $q = @$_SERVER['QUERY_STRING']; $fname .= '?'.preg_replace("/\W/", "_", $q).'.'.$img_format; } else { $fname = substr($fname,0,strlen($fname)-4).'.'.$img_format; } return $fname;}class LanguageConv { var $g2312 = null ; function Convert($aTxt,$aFF) { if( LANGUAGE_CYRILLIC ) { /* Auto-detect whether the cyrillic conversion ** based on the character_set info that has ** been passed to jpgraph from the including ** application. ** ** Call the cyrillic converter only when a cyrillic ** charset derivate is used. Otherwise do nothing ** and prevent from erraneously converted strings. */ if( CYRILLIC_FROM_WINDOWS && ( !defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'windows-1251') ) ) { $aTxt = convert_cyr_string($aTxt, "w", "k"); } if (!defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'koi8-r') || stristr(LANGUAGE_CHARSET, 'windows-1251')) { $isostring = convert_cyr_string($aTxt, "k", "i"); $unistring = LanguageConv::iso2uni($isostring); } else { $unistring = $aTxt; } return $unistring; } elseif( $aFF === FF_SIMSUN ) { // Do Chinese conversion if( $this->g2312 == null ) { include_once 'jpgraph_gb2312.php' ; $this->g2312 = new GB2312toUTF8(); } return $this->g2312->gb2utf8($aTxt); } elseif( $aFF === FF_CHINESE ) { if( !function_exists('iconv') ) { JpGraphError::RaiseL(25006);//('Usage of FF_CHINESE (FF_BIG5) font family requires that your PHP setup has the iconv() function. By default this is not compiled into PHP (needs the "--width-iconv" when configured).'); } return iconv('BIG5','UTF-8',$aTxt); } else return $aTxt; } // Translate iso encoding to unicode function iso2uni ($isoline){ $uniline=''; for ($i=0; $i < strlen($isoline); $i++){ $thischar=substr($isoline,$i,1); $charcode=ord($thischar); $uniline.=($charcode>175) ? "&#" . (1040+($charcode-176)). ";" : $thischar; } return $uniline; }}//===================================================// CLASS JpgTimer// Description: General timing utility class to handle// time measurement of generating graphs. Multiple// timers can be started.//===================================================class JpgTimer { var $start; var $idx; //---------------// CONSTRUCTOR function JpgTimer() { $this->idx=0; }//---------------// PUBLIC METHODS // Push a new timer start on stack function Push() { list($ms,$s)=explode(" ",microtime()); $this->start[$this->idx++]=floor($ms*1000) + 1000*$s; } // Pop the latest timer start and return the diff with the // current time function Pop() { assert($this->idx>0); list($ms,$s)=explode(" ",microtime()); $etime=floor($ms*1000) + (1000*$s); $this->idx--; return $etime-$this->start[$this->idx]; }} // Class$gJpgBrandTiming = BRAND_TIMING;//===================================================// CLASS DateLocale// Description: Hold localized text used in dates//===================================================class DateLocale { var $iLocale = 'C'; // environmental locale be used by default var $iDayAbb = null; var $iShortDay = null; var $iShortMonth = null; var $iMonthName = null;//---------------// CONSTRUCTOR function DateLocale() { settype($this->iDayAbb, 'array'); settype($this->iShortDay, 'array'); settype($this->iShortMonth, 'array'); settype($this->iMonthName, 'array'); $this->Set('C'); }//---------------// PUBLIC METHODS function Set($aLocale) { if ( in_array($aLocale, array_keys($this->iDayAbb)) ){ $this->iLocale = $aLocale; return TRUE; // already cached nothing else to do! } $pLocale = setlocale(LC_TIME, 0); // get current locale for LC_TIME $res = @setlocale(LC_TIME, $aLocale); if ( ! $res ){ JpGraphError::RaiseL(25007,$aLocale);//("You are trying to use the locale ($aLocale) which your PHP installation does not support. Hint: Use '' to indicate the default locale for this geographic region."); return FALSE; } $this->iLocale = $aLocale; for ( $i = 0, $ofs = 0 - strftime('%w'); $i < 7; $i++, $ofs++ ){ $day = strftime('%a', strtotime("$ofs day")); $day{0} = strtoupper($day{0}); $this->iDayAbb[$aLocale][]= $day{0}; $this->iShortDay[$aLocale][]= $day; } for($i=1; $i<=12; ++$i) { list($short ,$full) = explode('|', strftime("%b|%B",strtotime("2001-$i-01"))); $this->iShortMonth[$aLocale][] = ucfirst($short); $this->iMonthName [$aLocale][] = ucfirst($full); } // Return to original locale setlocale(LC_TIME, $pLocale); return TRUE; } function GetDayAbb() { return $this->iDayAbb[$this->iLocale]; } function GetShortDay() { return $this->iShortDay[$this->iLocale]; } function GetShortMonth() { return $this->iShortMonth[$this->iLocale]; } function GetShortMonthName($aNbr) { return $this->iShortMonth[$this->iLocale][$aNbr]; } function GetLongMonthName($aNbr) { return $this->iMonthName[$this->iLocale][$aNbr]; } function GetMonth() { return $this->iMonthName[$this->iLocale]; }}$gDateLocale = new DateLocale();$gJpgDateLocale = new DateLocale();//=======================================================// CLASS Footer// Description: Encapsulates the footer line in the Graph//=======================================================class Footer { var $left,$center,$right; var $iLeftMargin = 3; var $iRightMargin = 3; var $iBottomMargin = 3; function Footer() { $this->left = new Text(); $this->left->ParagraphAlign('left'); $this->center = new Text(); $this->center->ParagraphAlign('center'); $this->right = new Text(); $this->right->ParagraphAlign('right'); } function Stroke(&$aImg) { $y = $aImg->height - $this->iBottomMargin; $x = $this->iLeftMargin; $this->left->Align('left','bottom'); $this->left->Stroke($aImg,$x,$y); $x = ($aImg->width - $this->iLeftMargin - $this->iRightMargin)/2; $this->center->Align('center','bottom'); $this->center->Stroke($aImg,$x,$y); $x = $aImg->width - $this->iRightMargin; $this->right->Align('right','bottom'); $this->right->Stroke($aImg,$x,$y); }}//===================================================// CLASS Graph// Description: Main class to handle graphs//===================================================class Graph { var $cache=null; // Cache object (singleton) var $img=null; // Img object (singleton) var $plots=array(); // Array of all plot object in the graph (for Y 1 axis) var $y2plots=array();// Array of all plot object in the graph (for Y 2 axis) var $ynplots=array(); var $xscale=null; // X Scale object (could be instance of LinearScale or LogScale var $yscale=null,$y2scale=null, $ynscale=array(); var $iIcons = array(); // Array of Icons to add to 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; 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',
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -