⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpgraph_line.php

📁 一个基于web的开源项目管理工具
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/*=======================================================================// File: 	JPGRAPH_LINE.PHP// Description:	Line plot extension for JpGraph// Created: 	2001-01-08// Author:	Johan Persson (johanp@aditus.nu)// Ver:		$Id: jpgraph_line.php,v 1.3.10.1 2006/02/28 19:46:57 gregorerhardt Exp $//// Copyright (c) Aditus Consulting. All rights reserved.//========================================================================*/require_once ('jpgraph_plotmark.inc');// constants for the (filled) areaDEFINE("LP_AREA_FILLED", true);DEFINE("LP_AREA_NOT_FILLED", false);DEFINE("LP_AREA_BORDER",false);DEFINE("LP_AREA_NO_BORDER",true);//===================================================// CLASS LinePlot// Description: //===================================================class LinePlot extends Plot{    var $filled=false;    var $fill_color='blue';    var $mark=null;    var $step_style=false, $center=false;    var $line_style=1;	// Default to solid    var $filledAreas = array(); // array of arrays(with min,max,col,filled in them)    var $barcenter=false;  // When we mix line and bar. Should we center the line in the bar.    var $fillFromMin = false ;    var $fillgrad=false,$fillgrad_fromcolor='navy',$fillgrad_tocolor='silver',$fillgrad_numcolors=100;    var $iFastStroke=false;//---------------// CONSTRUCTOR    function LinePlot(&$datay,$datax=false) {	$this->Plot($datay,$datax);	$this->mark = new PlotMark();    }//---------------// PUBLIC METHODS	    // Set style, filled or open    function SetFilled($aFlag=true) {    	JpGraphError::RaiseL(10001);//('LinePlot::SetFilled() is deprecated. Use SetFillColor()');    }	    function SetBarCenter($aFlag=true) {	$this->barcenter=$aFlag;    }    function SetStyle($aStyle) {	$this->line_style=$aStyle;    }	    function SetStepStyle($aFlag=true) {	$this->step_style = $aFlag;    }	    function SetColor($aColor) {	parent::SetColor($aColor);    }	    function SetFillFromYMin($f=true) {	$this->fillFromMin = $f ;    }        function SetFillColor($aColor,$aFilled=true) {	$this->fill_color=$aColor;	$this->filled=$aFilled;    }    function SetFillGradient($aFromColor,$aToColor,$aNumColors=100,$aFilled=true) {	$this->fillgrad_fromcolor = $aFromColor;	$this->fillgrad_tocolor   = $aToColor;	$this->fillgrad_numcolors = $aNumColors;	$this->filled = $aFilled;	$this->fillgrad = true;    }	    function Legend(&$graph) {	if( $this->legend!="" ) {	    if( $this->filled && !$this->fillgrad ) {		$graph->legend->Add($this->legend,				    $this->fill_color,$this->mark,0,				    $this->legendcsimtarget,$this->legendcsimalt);	    } 	    elseif( $this->fillgrad ) {		$color=array($this->fillgrad_fromcolor,$this->fillgrad_tocolor);		// In order to differentiate between gradients and cooors specified as an RGB triple		$graph->legend->Add($this->legend,$color,"",-2 /* -GRAD_HOR */,				    $this->legendcsimtarget,$this->legendcsimalt);	    }		    else {		$graph->legend->Add($this->legend,				    $this->color,$this->mark,$this->line_style,				    $this->legendcsimtarget,$this->legendcsimalt);	    }	}	    }    function AddArea($aMin=0,$aMax=0,$aFilled=LP_AREA_NOT_FILLED,$aColor="gray9",$aBorder=LP_AREA_BORDER) {	if($aMin > $aMax) {	    // swap	    $tmp = $aMin;	    $aMin = $aMax;	    $aMax = $tmp;	} 	$this->filledAreas[] = array($aMin,$aMax,$aColor,$aFilled,$aBorder);    }	    // Gets called before any axis are stroked    function PreStrokeAdjust(&$graph) {	// If another plot type have already adjusted the	// offset we don't touch it.	// (We check for empty in case the scale is  a log scale 	// and hence doesn't contain any xlabel_offset)	if( empty($graph->xaxis->scale->ticks->xlabel_offset) ||	    $graph->xaxis->scale->ticks->xlabel_offset == 0 ) {	    if( $this->center ) {		++$this->numpoints;		$a=0.5; $b=0.5;	    } else {		$a=0; $b=0;	    }	    $graph->xaxis->scale->ticks->SetXLabelOffset($a);	    $graph->SetTextScaleOff($b);							    //$graph->xaxis->scale->ticks->SupressMinorTickMarks();	}    }    function SetFastStroke($aFlg=true) {	$this->iFastStroke = $aFlg;    }    function FastStroke(&$img,&$xscale,&$yscale,$aStartPoint=0,$exist_x=true) {	// An optimized stroke for many data points with no extra 	// features but 60% faster. You can't have values or line styles, or null	// values in plots.	$numpoints=count($this->coords[0]);	if( $this->barcenter ) 	    $textadj = 0.5-$xscale->text_scale_off;	else	    $textadj = 0;	$img->SetColor($this->color);	$img->SetLineWeight($this->weight);	$pnts=$aStartPoint;	while( $pnts < $numpoints ) {	    	    if( $exist_x ) $x=$this->coords[1][$pnts];	    else $x=$pnts+$textadj;	    $xt = $xscale->Translate($x);	    $y=$this->coords[0][$pnts];	    $yt = $yscale->Translate($y);    	    if( is_numeric($y) ) {		$cord[] = $xt;		$cord[] = $yt;	    }	    elseif( $y == '-' && $pnts > 0 ) {		// Just ignore	    }	    else {		JpGraphError::RaiseL(10002);//('Plot too complicated for fast line Stroke. Use standard Stroke()');		return;	    }	    ++$pnts;	} // WHILE	$img->Polygon($cord,false,true);    }	    function Stroke(&$img,&$xscale,&$yscale) {	$idx=0;	$numpoints=count($this->coords[0]);	if( isset($this->coords[1]) ) {	    if( count($this->coords[1])!=$numpoints )		JpGraphError::RaiseL(2003,count($this->coords[1]),$numpoints);//("Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])." Number of Y-points:$numpoints");	    else		$exist_x = true;	}	else 	    $exist_x = false;	if( $this->barcenter ) 	    $textadj = 0.5-$xscale->text_scale_off;	else	    $textadj = 0;	// Find the first numeric data point	$startpoint=0;	while( $startpoint < $numpoints && !is_numeric($this->coords[0][$startpoint]) )	    ++$startpoint;	// Bail out if no data points	if( $startpoint == $numpoints ) 	    return;	if( $this->iFastStroke ) {	    $this->FastStroke($img,$xscale,$yscale,$startpoint,$exist_x);	    return;	}	if( $exist_x )	    $xs=$this->coords[1][$startpoint];	else	    $xs= $textadj+$startpoint;	$img->SetStartPoint($xscale->Translate($xs),			    $yscale->Translate($this->coords[0][$startpoint]));	if( $this->filled ) {	    $min = $yscale->GetMinVal();	    if( $min > 0 || $this->fillFromMin )		$fillmin = $yscale->scale_abs[0];//Translate($min);	    else		$fillmin = $yscale->Translate(0);	    $cord[$idx++] = $xscale->Translate($xs);	    $cord[$idx++] = $fillmin;	}	$xt = $xscale->Translate($xs);	$yt = $yscale->Translate($this->coords[0][$startpoint]);	$cord[$idx++] = $xt;	$cord[$idx++] = $yt;	$yt_old = $yt;	$xt_old = $xt;	$y_old = $this->coords[0][$startpoint];	$this->value->Stroke($img,$this->coords[0][$startpoint],$xt,$yt);	$img->SetColor($this->color);	$img->SetLineWeight($this->weight);	$img->SetLineStyle($this->line_style);	$pnts=$startpoint+1;	$firstnonumeric = false;	while( $pnts < $numpoints ) {	    	    if( $exist_x ) $x=$this->coords[1][$pnts];	    else $x=$pnts+$textadj;	    $xt = $xscale->Translate($x);	    $yt = $yscale->Translate($this->coords[0][$pnts]);	    	    $y=$this->coords[0][$pnts];	    if( $this->step_style ) {		// To handle null values within step style we need to record the		// first non numeric value so we know from where to start if the		// non value is '-'. 		if( is_numeric($y) ) {		    $firstnonumeric = false;		    if( is_numeric($y_old) ) {			$img->StyleLine($xt_old,$yt_old,$xt,$yt_old);			$img->StyleLine($xt,$yt_old,$xt,$yt);		    }		    elseif( $y_old == '-' ) {			$img->StyleLine($xt_first,$yt_first,$xt,$yt_first);			$img->StyleLine($xt,$yt_first,$xt,$yt);					    }		    else {			$yt_old = $yt;			$xt_old = $xt;		    }		    $cord[$idx++] = $xt;		    $cord[$idx++] = $yt_old;		    $cord[$idx++] = $xt;		    $cord[$idx++] = $yt;		}		elseif( $firstnonumeric==false ) {		    $firstnonumeric = true;		    $yt_first = $yt_old;		    $xt_first = $xt_old;		}	    }	    else {		$tmp1=$y;		$prev=$this->coords[0][$pnts-1]; 		 					if( $tmp1==='' || $tmp1===NULL || $tmp1==='X' ) $tmp1 = 'x';		if( $prev==='' || $prev===null || $prev==='X' ) $prev = 'x';		if( is_numeric($y) || (is_string($y) && $y != '-') ) {		    if( is_numeric($y) && (is_numeric($prev) || $prev === '-' ) ) { 			$img->StyleLineTo($xt,$yt);		    } 		    else {			$img->SetStartPoint($xt,$yt);		    }		}		if( $this->filled && $tmp1 !== '-' ) {		    if( $tmp1 === 'x' ) { 			$cord[$idx++] = $cord[$idx-3];			$cord[$idx++] = $fillmin;		    }		    elseif( $prev === 'x' ) {			$cord[$idx++] = $xt;			$cord[$idx++] = $fillmin;			$cord[$idx++] = $xt;			$cord[$idx++] = $yt; 			    		    }		    else {			$cord[$idx++] = $xt;			$cord[$idx++] = $yt;		    }		}		else {		    if( is_numeric($tmp1)  && (is_numeric($prev) || $prev === '-' ) ) {			$cord[$idx++] = $xt;			$cord[$idx++] = $yt;		    } 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -