Example #1
0
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_matrix.php';
$data = array(array(0, null, 2, 3, 4, 5, 6, 7, 8, 9, 10, 8, 6, 4, 2), array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 8, 5, 9, 2), array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 4, 5, 7), array(10, 9, 8, 17, 6, 5, 4, 3, 2, 1, 0, 8, 6, 4, 2), array(0, 1, 2, 3, 4, 4, 9, 7, 8, 9, 10, 3, 2, 7, 2), array(8, 1, 2, 3, 4, 8, 3, 7, 8, 9, 10, 5, 3, 9, 1), array(10, 3, 5, 7, 6, 5, 4, 3, 12, 1, 0, 6, 5, 10, 2), array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, NULL, 8, 6, 4, 2));
for ($i = 0; $i < count($data[0]); ++$i) {
    $xlabels[$i] = sprintf('xlabel: %02d', $i);
}
for ($i = 0; $i < count($data); ++$i) {
    $ylabels[$i] = sprintf('ylabel: %02d', $i);
}
// Setup a nasic matrix graph
$graph = new MatrixGraph(400, 250);
$graph->SetMarginColor('white');
$graph->title->Set('Adding labels on the edges');
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 14);
// Create one matrix plot
$mp = new MatrixPlot($data, 1);
$mp->SetModuleSize(13, 15);
$mp->SetCenterPos(0.35, 0.45);
$mp->colormap->SetNullColor('gray');
// Setup column lablels
$mp->collabel->Set($xlabels);
$mp->collabel->SetSide('bottom');
$mp->collabel->SetFont(FF_ARIAL, FS_NORMAL, 8);
$mp->collabel->SetFontColor('darkgray');
// Setup row lablels
$mp->rowlabel->Set($ylabels);
$mp->rowlabel->SetSide('right');
$mp->rowlabel->SetFont(FF_ARIAL, FS_NORMAL, 8);
$mp->rowlabel->SetFontColor('darkgray');
// Move the legend more to the right
$mp->legend->SetMargin(90);
Example #2
0
<?php

require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_matrix.php';
require_once 'jpgraph/jpgraph_iconplot.php';
$data = array(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0), array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), array(10, 9, 8, 17, 6, 5, 4, 3, 2, 1, 0), array(0, 1, 2, 3, 4, 4, 9, 7, 8, 9, 10), array(8, 1, 2, 3, 4, 8, 3, 7, 8, 9, 10), array(10, 3, 5, 7, 6, 5, 4, 3, 12, 1, 0), array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0));
// Do the meshinterpolation once for the data
doMeshInterpolate($data, 4);
$r = count($data);
$c = count($data[0]);
$width = 400;
$height = 400;
$graph = new MatrixGraph($width, $height);
$graph->title->Set('Adding a background image');
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 14);
// Add a stretched background image
$graph->SetBackgroundImage('ironrod.jpg', BGIMG_FILLFRAME);
$graph->SetBackgroundImageMix(50);
$mp = new MatrixPlot($data, 1);
$mp->SetSize(0.6);
$mp->SetCenterPos(0.5, 0.5);
$mp->SetLegendLayout(1);
$graph->Add($mp);
$graph->Stroke();
 /**
  * Internal. Stroke labels
  * @param MatrixPlot $aMPlot
  * @param Image $aImg
  */
 function Stroke(MatrixPlot $aMPlot, Image $aImg)
 {
     $t = new Text();
     $t->SetColor($this->iColor);
     $t->SetFont($this->iFF, $this->iFS, $this->iFSize);
     $n = count($this->iLabels);
     $rows = count($aMPlot->iData);
     $cols = count($aMPlot->iData[0]);
     list($modwidth, $modheight) = $aMPlot->GetModSizes();
     $x = $this->iStartX;
     $y = $this->iStartY;
     if (!empty($this->csimtargets) || is_array($this->csimtargets) && count($this->csimtargets) == 0) {
         $csn = count($this->csimtargets);
         if ($csn != $n) {
             JpGraphError::RaiseL(29210, $csn, $n);
             // CSIM Target for matrix labels must be the same length as the labels
         }
     }
     $csim = '';
     switch ($this->iSide) {
         case 'top':
         case 'bottom':
             $t->SetAngle($this->iAngle);
             $x += round($modwidth / 2);
             if ($this->iSide == 'top') {
                 $y -= $this->iMargin;
                 $t->SetAlign('center', 'bottom');
             } else {
                 $y += $this->iMargin + $rows * $modheight;
                 if ($this->iAngle > 0 && $this->iAngle < 90) {
                     $t->SetAlign('right', 'top');
                 } else {
                     $t->SetAlign('center', 'top');
                 }
             }
             for ($i = 0; $i < $n && $i < $cols; ++$i, $x += $modwidth) {
                 $t->Set($this->iLabels[$i]);
                 if (!empty($this->csimtargets)) {
                     if (!empty($this->csimalts[$i]) && !empty($this->csimwintargets[$i])) {
                         $t->SetCSIMTarget($this->csimtargets[$i], $this->csimalts[$i], $this->csimwintargets[$i]);
                     } elseif (!empty($this->csimalts[$i])) {
                         $t->SetCSIMTarget($this->csimtargets[$i], $this->csimalts[$i]);
                     } elseif (!empty($this->csimwintargets[$i])) {
                         $t->SetCSIMTarget($this->csimtargets[$i], '', $this->csimwintargets[$i]);
                     } else {
                         $t->SetCSIMTarget($this->csimtargets[$i]);
                     }
                 }
                 $t->Stroke($aImg, $x, $y);
                 $csim .= $t->GetCSIMareas();
             }
             break;
         case 'left':
         case 'right':
             $t->SetAngle($this->iAngle);
             $y += round($modheight / 2);
             if ($this->iSide == 'left') {
                 $x -= $this->iMargin + 1;
                 $t->SetAlign('right', 'center');
             } else {
                 $x += $this->iMargin + $cols * $modwidth;
                 $t->SetAlign('left', 'center');
             }
             for ($i = 0; $i < $n && $i < $rows; ++$i, $y += $modheight) {
                 $t->Set($this->iLabels[$i]);
                 if (!empty($this->csimtargets)) {
                     if (!empty($this->csimalts[$i]) && !empty($this->csimwintargets[$i])) {
                         $t->SetCSIMTarget($this->csimtargets[$i], $this->csimalts[$i], $this->csimwintargets[$i]);
                     } elseif (!empty($this->csimalts[$i])) {
                         $t->SetCSIMTarget($this->csimtargets[$i], $this->csimalts[$i]);
                     } elseif (!empty($this->csimwintargets[$i])) {
                         $t->SetCSIMTarget($this->csimtargets[$i], '', $this->csimwintargets[$i]);
                     } else {
                         $t->SetCSIMTarget($this->csimtargets[$i]);
                     }
                 }
                 $t->Stroke($aImg, $x, $y);
                 $csim .= $t->GetCSIMareas();
             }
             break;
     }
     $this->csimareas = $csim;
 }
Example #4
0
    $collabels[$i] = sprintf('column label: %02d', $i);
}
for ($i = 0; $i < $ny; ++$i) {
    $rowlabels[$i] = sprintf('row label: %02d', $i);
}
// Setup a nasic matrix graph
$graph = new MatrixGraph(400, 350);
$graph->SetBackgroundGradient('lightsteelblue:0.8', 'lightsteelblue:0.3');
$graph->title->Set('Matrix with lines');
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 18);
$graph->title->SetColor('white');
// Create two lines to add as markers
$l1 = new PlotLine(VERTICAL, 5, 'lightgray:1.5', 4);
$l2 = new PlotLine(HORIZONTAL, 3, 'lightgray:1.5', 4);
// Create one matrix plot
$mp = new MatrixPlot($data, 1);
$mp->SetModuleSize(13, 15);
$mp->SetCenterPos(0.35, 0.6);
$mp->colormap->SetNullColor('gray');
// Add lines
$mp->AddLine($l1);
$mp->AddLine($l2);
// this could also be done as
// $mp->AddLine(array($l1,$l2));
// Setup column lablels
$mp->collabel->Set($collabels);
$mp->collabel->SetSide('top');
$mp->collabel->SetFont(FF_ARIAL, FS_NORMAL, 8);
$mp->collabel->SetFontColor('lightgray');
// Setup row lablels
$mp->rowlabel->Set($rowlabels);
Example #5
0
for ($i = 0; $i < $nx; ++$i) {
    $collabels[$i] = sprintf('column label: %02d', $i);
    $collabeltargets[$i] = '#' . sprintf('collabel: %02d', $i);
}
for ($i = 0; $i < $ny; ++$i) {
    $rowlabels[$i] = sprintf('row label: %02d', $i);
    $rowlabeltargets[$i] = '#' . sprintf('rowlabel: %02d', $i);
}
// Setup a nasic matrix graph
$graph = new MatrixGraph(400, 350);
$graph->SetBackgroundGradient('lightsteelblue:0.8', 'lightsteelblue:0.3');
$graph->title->Set('CSIM with matrix');
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 16);
$graph->title->SetColor('white');
// Create one matrix plot
$mp = new MatrixPlot($data, 1);
$mp->SetModuleSize(13, 15);
$mp->SetCenterPos(0.35, 0.6);
$mp->colormap->SetNullColor('gray');
// Setup column lablels
$mp->collabel->Set($collabels);
$mp->collabel->SetSide('top');
$mp->collabel->SetFont(FF_ARIAL, FS_NORMAL, 8);
$mp->collabel->SetFontColor('lightgray');
// Setup row lablels
$mp->rowlabel->Set($rowlabels);
$mp->rowlabel->SetSide('right');
$mp->rowlabel->SetFont(FF_ARIAL, FS_NORMAL, 8);
$mp->rowlabel->SetFontColor('lightgray');
$mp->rowlabel->SetCSIMTargets($rowlabeltargets);
$mp->collabel->SetCSIMTargets($collabeltargets);
Example #6
0
<?php

require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_matrix.php';
require_once 'jpgraph/jpgraph_iconplot.php';
$data = array(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0), array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), array(10, 9, 8, 17, 6, 5, 4, 3, 2, 1, 0), array(0, 1, 2, 3, 4, 4, 9, 7, 8, 9, 10), array(8, 1, 2, 3, 4, 8, 3, 7, 8, 9, 10), array(10, 3, 5, 7, 6, 5, 4, 3, 12, 1, 0), array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0));
$nrow = count($data);
$ncol = count($data[0]);
$width = 350;
$height = 300;
$graph = new MatrixGraph($width, $height);
$graph->title->Set('Add ine row/col labels');
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 14);
$mp = new MatrixPlot($data, 1);
$mp->SetSize(0.55);
$mp->SetCenterPos(0.45, 0.45);
$rowtitles = array();
for ($i = 0; $i < $nrow; ++$i) {
    $rowtitles[$i] = sprintf('Row: %02d', $i);
}
$coltitles = array();
for ($i = 0; $i < $ncol; ++$i) {
    $coltitles[$i] = sprintf('Col: %02d', $i);
}
$mp->rowlabel->Set($rowtitles);
$mp->rowlabel->SetFont(FF_ARIAL, FS_NORMAL, 10);
$mp->rowlabel->SetFontColor('blue');
$mp->rowlabel->SetSide('left');
$mp->collabel->Set($coltitles);
$mp->collabel->SetFont(FF_ARIAL, FS_NORMAL, 10);
$mp->collabel->SetFontColor('darkred');
Example #7
0
<?php

require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_matrix.php';
$data = array(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0), array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), array(10, 9, 8, 17, 6, 5, 4, 3, 2, 1, 0), array(0, 1, 2, 3, 4, 4, 9, 7, 8, 9, 10), array(8, 1, 2, 3, 4, 8, 3, 7, 8, 9, 10), array(10, 3, 5, 7, 6, 5, 4, 3, 12, 1, 0), array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0));
$width = 400;
$height = 350;
$graph = new MatrixGraph($width, $height);
$graph->title->Set('Using a circular module type');
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 14);
$mp = new MatrixPlot($data, 2);
$mp->SetSize(0.85);
$mp->SetModuleType(1);
$mp->SetBackgroundColor('teal:1.8');
$mp->SetCenterPos(0.5, 0.45);
$mp->SetLegendLayout(1);
$graph->Add($mp);
$graph->Stroke();
Example #8
0
<?php

require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_matrix.php';
$data = array(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0), array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), array(10, 9, 8, 17, 6, 5, 4, 3, 2, 1, 0), array(0, 1, 2, 3, 4, 4, 9, 7, 8, 9, 10), array(8, 1, 2, 3, 4, 8, 3, 7, 8, 9, 10), array(10, 3, 5, 7, 6, 5, 4, 3, 12, 1, 0), array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0));
// Do the meshinterpolation once for the data
doMeshInterpolate($data, 3);
$r = count($data);
$c = count($data[0]);
$graph = new MatrixGraph(250, 220);
$graph->title->Set('Meshinterpolation=3');
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 14);
$mp = new MatrixPlot($data, 1);
$mp->colormap->SetMap(0);
$mp->SetSize(200, 160);
$mp->SetCenterPos(0.5, 0.55);
$mp->legend->Show(false);
$graph->Add($mp);
$graph->Stroke();
Example #9
0
<?php

require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_matrix.php';
require_once 'jpgraph/jpgraph_iconplot.php';
$data = array(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0), array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), array(10, 9, 8, 17, 6, 5, 4, 3, 2, 1, 0), array(0, 1, 2, 3, 4, 4, 9, 7, 8, 9, 10), array(8, 1, 2, 3, 4, 8, 3, 7, 8, 9, 10), array(10, 3, 5, 7, 6, 5, 4, 3, 12, 1, 0), array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0));
// Do the meshinterpolation once for the data
doMeshInterpolate($data, 3);
$r = count($data);
$c = count($data[0]);
$width = 400;
$height = 400;
$graph = new MatrixGraph($width, $height);
$graph->title->Set('Adding an icon to the background');
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 14);
$mp = new MatrixPlot($data, 1);
$mp->SetSize(0.6);
$icon = new IconPlot('icon.jpg', $width - 1, $height - 1, 0.8, 50);
$icon->SetAnchor('right', 'bottom');
$graph->Add($icon);
$graph->Add($mp);
$graph->Stroke();