예제 #1
0
include "../jpgraph_utils.inc.php";
//
// Create some random data for the plot. We use the current time for the
// first X-position
//
$datay = array();
$datax = array();
$ts = time();
$n = 15;
// Number of data points
for ($i = 0; $i < $n; ++$i) {
    $datax[$i] = $ts + $i * 700000;
    $datay[$i] = rand(5, 60);
}
// Now get labels at the start of each month
list($tickPositions, $minTickPositions) = DateScaleUtils::GetTicks($datax);
// We add some grace to the end of the X-axis scale so that the first and last
// data point isn't exactly at the very end or beginning of the scale
$grace = 400000;
$xmin = $datax[0] - $grace;
$xmax = $datax[$n - 1] + $grace;
//
// The code to setup a very basic graph
//
$graph = new Graph(400, 200);
//
// We use an integer scale on the X-axis since the positions on the X axis
// are assumed to be UNI timestamps
$graph->SetScale('intlin', 0, 0, $xmin, $xmax);
$graph->title->Set('Basic example with manual ticks');
$graph->title->SetFont(FF_ARIAL, FS_NORMAL, 12);
예제 #2
0
//------------------------------------------------------------------
// Create some random data for the plot. We use the current time for the
// first X-position
//------------------------------------------------------------------
$datay = array();
$datax = array();
$ts = time();
$n = 70;
// Number of data points
for ($i = 0; $i < $n; ++$i) {
    $datax[$i] = $ts + $i * 150000;
    $datay[$i] = rand(5, 60);
    $datay2[$i] = rand(1, 8);
}
// Now get labels at the start of each month
$dateUtils = new DateScaleUtils();
list($tickPositions, $minTickPositions) = $dateUtils->getTicks($datax, DSUTILS_MONTH1);
// Now create the real graph
// Combine a line and a bar graph
// We add some grace to the end of the X-axis scale so that the first and last
// data point isn't exactly at the very end or beginning of the scale
$grace = 400000;
$xmin = $datax[0] - $grace;
$xmax = $datax[$n - 1] + $grace;
// Overall width of graphs
$w = 450;
// Left and right margin for each graph
$lm = 25;
$rm = 15;
//----------------------
// Setup the line graph
예제 #3
0
 static function GetTicksFromMinMax($aMin, $aMax, $aType, $aMinor = false, $aEndPoints = false)
 {
     self::$starthour = date('G', $aMin);
     self::$startmonth = date('n', $aMin);
     self::$startday = date('j', $aMin);
     self::$startyear = date('Y', $aMin);
     self::$endmonth = date('n', $aMax);
     self::$endyear = date('Y', $aMax);
     self::$endday = date('j', $aMax);
     self::$iMin = $aMin;
     self::$iMax = $aMax;
     if ($aType <= DSUTILS_MONTH6) {
         self::doMonthly($aType, $aMinor);
     } elseif ($aType <= DSUTILS_WEEK4) {
         self::doWeekly($aType, $aMinor);
     } elseif ($aType <= DSUTILS_DAY4) {
         self::doDaily($aType, $aMinor);
     } elseif ($aType <= DSUTILS_YEAR5) {
         self::doYearly($aType, $aMinor);
     } else {
         JpGraphError::RaiseL(24003);
     }
     // put a label at the very left data pos
     if ($aEndPoints) {
         $tickPositions[$i++] = $aData[0];
     }
     // put a label at the very right data pos
     if ($aEndPoints) {
         $tickPositions[$i] = $aData[$n - 1];
     }
     return array(self::$tickPositions, self::$minTickPositions);
 }
예제 #4
0
//------------------------------------------------------------------
// Create some random data for the plot. We use the current time for the
// first X-position
//------------------------------------------------------------------
$datay = array();
$datax = array();
$ts = time();
$n = 70;
// Number of data points
for ($i = 0; $i < $n; ++$i) {
    $datax[$i] = $ts + $i * 150000;
    $datay[$i] = rand(5, 60);
    $datay2[$i] = rand(1, 8);
}
// Now get labels at the start of each month
list($tickPositions, $minTickPositions) = DateScaleUtils::getTicks($datax, DSUTILS_MONTH1);
// Now create the real graph
// Combine a line and a bar graph
// We add some grace to the end of the X-axis scale so that the first and last
// data point isn't exactly at the very end or beginning of the scale
$grace = 400000;
$xmin = $datax[0] - $grace;
$xmax = $datax[$n - 1] + $grace;
// Overall width of graphs
$w = 450;
// Left and right margin for each graph
$lm = 25;
$rm = 15;
//----------------------
// Setup the line graph
//----------------------
예제 #5
0
 /**
  * Executes test action
  *
  */
 public function executeTest()
 {
     /*
         In order to use fonts, you must define the location to your fonts:
         define('TTF_DIR', '/usr/X11R6/share/fonts/ttf/');
     */
     //------------------------------------------------------------------
     // Create some random data for the plot. We use the current time for the
     // first X-position
     //------------------------------------------------------------------
     $datay = array();
     $datax = array();
     $ts = time();
     $n = 70;
     // Number of data points
     for ($i = 0; $i < $n; ++$i) {
         $datax[$i] = $ts + $i * 150000;
         $datay[$i] = rand(5, 60);
         $datay2[$i] = rand(1, 8);
     }
     // Now get labels at the start of each month
     $date = new DateScaleUtils();
     list($tickPositions, $minTickPositions) = $date->getTicks($datax, DSUTILS_MONTH1);
     // Now create the real graph
     // Combine a line and a bar graph
     // We add some grace to the end of the X-axis scale so that the first and last
     // data point isn't exactly at the very end or beginning of the scale
     $grace = 400000;
     $xmin = $datax[0] - $grace;
     $xmax = $datax[$n - 1] + $grace;
     // Overall width of graphs
     $w = 450;
     // Left and right margin for each graph
     $lm = 25;
     $rm = 15;
     //----------------------
     // Setup the line graph
     //----------------------
     $graph = new sfJpGraph('line', $w, 250);
     $graph = $graph->getJpGraph();
     $graph->SetScale('linlin', 0, 0, $xmin, $xmax);
     $graph->SetMargin($lm, $rm, 10, 30);
     $graph->SetMarginColor('white');
     $graph->SetFrame(false);
     $graph->SetBox(true);
     $graph->xaxis->SetTickPositions($tickPositions, $minTickPositions);
     $graph->xaxis->SetLabelFormatString('My', true);
     $graph->xgrid->Show();
     $p1 = new LinePlot($datay, $datax);
     $graph->Add($p1);
     //----------------------
     // Setup the bar graph
     //----------------------
     $graph2 = new sfJpGraph('bar', $w, 110);
     $graph2 = $graph2->getJpGraph();
     $graph2->SetScale('linlin', 0, 0, $xmin, $xmax);
     $graph2->SetMargin($lm, $rm, 5, 10);
     $graph2->SetMarginColor('white');
     $graph2->SetFrame(false);
     $graph2->SetBox(true);
     $graph2->xgrid->Show();
     $graph2->xaxis->SetTickPositions($tickPositions, $minTickPositions);
     $graph2->xaxis->SetLabelFormatString('My', true);
     $graph2->xaxis->SetPos('max');
     $graph2->xaxis->HideLabels();
     $graph2->xaxis->SetTickSide(SIDE_DOWN);
     $b1 = new BarPlot($datay2, $datax);
     $b1->SetFillColor('teal');
     $b1->SetColor('teal:1.2');
     $graph2->Add($b1);
     //-----------------------
     // Create a multigraph
     //----------------------
     $mgraph = new sfJpGraph('mgraph', $w, 110);
     $mgraph = $mgraph->getJpGraph();
     $mgraph->SetImgFormat('jpeg', 60);
     $mgraph->SetMargin(2, 2, 2, 2);
     $mgraph->SetFrame(true);
     $mgraph->AddMix($graph, 0, 0, 85);
     $mgraph->AddMix($graph2, 0, 250, 85);
     $mgraph->Stroke();
     return sfView::NONE;
 }
예제 #6
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_utils.inc.php';
// Get a dataset stored in $xdata and $ydata
require_once 'dataset01.inc.php';
$dateUtils = new DateScaleUtils();
// Setup a basic graph
$width = 500;
$height = 300;
$graph = new Graph($width, $height);
// We set the x-scale min/max values to avoid empty space
// on the side of the plot
$graph->SetScale('intlin', 0, 0, min($xdata), max($xdata));
$graph->SetMargin(60, 20, 40, 60);
// Setup the titles
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 12);
$graph->title->Set('Development since 1984');
$graph->subtitle->SetFont(FF_ARIAL, FS_ITALIC, 10);
$graph->subtitle->Set('(Example using DateScaleUtils class)');
// Setup the labels to be correctly format on the X-axis
$graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8);
$graph->xaxis->SetLabelAngle(30);
// The second paramter set to 'true' will make the library interpret the
// format string as a date format. We use a Month + Year format
$graph->xaxis->SetLabelFormatString('M, Y', true);
// Get manual tick every second year
list($tickPos, $minTickPos) = $dateUtils->getTicks($xdata, DSUTILS_YEAR2);
$graph->xaxis->SetTickPositions($tickPos, $minTickPos);
예제 #7
0
require_once 'jpgraph/jpgraph_utils.inc.php';
//
// Create some random data for the plot. We use the current time for the
// first X-position
//
$datay = array();
$datax = array();
$ts = time();
$n = 15;
// Number of data points
for ($i = 0; $i < $n; ++$i) {
    $datax[$i] = $ts + $i * 700000;
    $datay[$i] = rand(5, 60);
}
// Now get labels at the start of each month
$dateUtils = new DateScaleUtils();
list($tickPositions, $minTickPositions) = $dateUtils->GetTicks($datax);
// We add some grace to the end of the X-axis scale so that the first and last
// data point isn't exactly at the very end or beginning of the scale
$grace = 400000;
$xmin = $datax[0] - $grace;
$xmax = $datax[$n - 1] + $grace;
//
// The code to setup a very basic graph
//
$graph = new Graph(400, 200);
//
// We use an integer scale on the X-axis since the positions on the X axis
// are assumed to be UNI timestamps
$graph->SetScale('intlin', 0, 0, $xmin, $xmax);
$graph->title->Set('Basic example with manual ticks');
예제 #8
0
 function postProcess()
 {
     global $jpgraphTimeAlign, $jpgraphTickAlign, $dateUtils;
     $this->color_list = split(",", $this->colors);
     if ($this->hasxgrid) {
         $this->graph->xgrid->Show();
     }
     if ($this->hasygrid) {
         $this->graph->ygrid->Show();
     }
     if ($this->xlabel) {
         $this->graph->xaxis->title->Set($this->xlabel);
     }
     if ($this->ylabel) {
         $this->graph->yaxis->title->Set($this->ylabel);
     }
     if ($this->xlabelformat) {
         $this->graph->xaxis->SetLabelFormatString($this->xlabelformat, $this->xistime);
     }
     if ($this->ylabelformat) {
         $this->graph->yaxis->SetLabelFormatString($this->ylabelformat);
     }
     if ($this->fill) {
         $tmp = split(",", $this->fill);
         if (count($tmp) == 2) {
             $this->graph->ygrid->SetFill(true, $tmp[0], $tmp[1]);
         } else {
             if (count($tmp) == 1) {
                 $this->graph->ygrid->SetFill(true, $tmp[0], $tmp[0]);
             } else {
                 throw new JpgraphMWException("Error while parsing fill value (" . $this->fill . ").");
             }
         }
     }
     if ($this->dateformat) {
         $this->graph->xaxis->scale->SetDateFormat($this->dateformat);
     }
     if ($this->usettf) {
         $this->graph->xaxis->SetFont($this->font);
         $this->graph->yaxis->SetFont($this->font);
         $this->graph->xaxis->title->SetFont($this->font);
         $this->graph->yaxis->title->SetFont($this->font);
         $this->graph->xaxis->SetLabelAngle($this->rotatexlegend);
         $this->graph->yaxis->SetLabelAngle($this->rotateylegend);
         $this->graph->legend->SetFont($this->font);
     }
     if ($this->legendposition) {
         $tmp = split(",", $this->legendposition);
         $this->graph->legend->Pos($tmp[0], $tmp[1]);
     }
     $this->graph->yaxis->scale->SetAutoMin($this->min);
     $this->graph->yaxis->scale->SetAutoMax($this->max);
     if ($this->timealign) {
         $timealign = split(",", $this->timealign);
         $this->graph->xaxis->scale->SetDateAlign($jpgraphTimeAlign[$timealign[0]], $jpgraphTimeAlign[$timealign[1]]);
     }
     if ($this->tickalign) {
         $dateUtils = new DateScaleUtils();
         list($tickPos, $minTickPos) = $dateUtils->getTicks($this->datax, $jpgraphTickAlign[$this->tickalign]);
         $this->graph->xaxis->SetTickPositions($tickPos, $minTickPos);
     }
 }