PHP - Gráficos



 

example14.php

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_error.php');

$errdatay = array(11,9,2,4,19,26,13,19,7,12);


// Create the graph. These two calls are always required
$graph = new Graph(300,200);
$graph->clearTheme();
$graph->SetScale("textlin");

$graph->img->SetMargin(40,30,20,40);
$graph->SetShadow();

// Create the error plot
$errplot=new ErrorPlot($errdatay);
$errplot->SetColor("red");
$errplot->SetWeight(2);
$errplot->SetCenter();

// Add the plot to the graph
$graph->Add($errplot);

$graph->title->Set("Simple error plot");
$graph->xaxis->title->Set("X-title");
$graph->yaxis->title->Set("Y-title");

$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

$datax = $gDateLocale->GetShortMonth();
$graph->xaxis->SetTickLabels($datax);

// Display the graph
$graph->Stroke();

 

 

example26.1.php

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_pie.php');

$data = array(40,60,21,33);

$graph = new PieGraph(300,200);
$graph->clearTheme();
$graph->SetShadow();

$graph->title->Set("A simple Pie plot");
$graph->title->SetFont(FF_FONT1,FS_BOLD);

$p1 = new PiePlot($data);
$p1->SetLegends($gDateLocale->GetShortMonth());
$p1->SetCenter(0.4);

$graph->Add($p1);
$graph->Stroke();

 

 

example27.1.php

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_pie.php');
require_once ('jpgraph/jpgraph_pie3d.php');

$data = array(40,60,21,33);

$graph = new PieGraph(300,200);
$graph->clearTheme();
$graph->SetShadow();

$graph->title->Set("A simple Pie plot");
$graph->title->SetFont(FF_FONT1,FS_BOLD);

$p1 = new PiePlot3D($data);
$p1->SetAngle(20);
$p1->SetSize(0.5);
$p1->SetCenter(0.45);
$p1->SetLegends($gDateLocale->GetShortMonth());

$graph->Add($p1);
$graph->Stroke();

 

 

example27.3.php

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_pie.php');
require_once ('jpgraph/jpgraph_pie3d.php');

$data = array(40,60,21,33);

$graph = new PieGraph(330,200);
$graph->clearTheme();
$graph->SetShadow();

$graph->title->Set("A simple 3D Pie plot");
$graph->title->SetFont(FF_FONT1,FS_BOLD);

$p1 = new PiePlot3D($data);
$p1->ExplodeSlice(1);
$p1->SetCenter(0.45);
$p1->SetLegends($gDateLocale->GetShortMonth());

$graph->Add($p1);
$graph->Stroke();

 

 

fixscale_radarex1.php

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_radar.php');

$graph = new RadarGraph(300,300);
$graph->SetScale('lin',0,50);
$graph->yscale->ticks->Set(25,5);
$graph->SetColor('white');
$graph->SetShadow();

$graph->SetCenter(0.5,0.55);

$graph->axis->SetFont(FF_FONT1,FS_BOLD);
$graph->axis->SetWeight(2);

// Uncomment the following lines to also show grid lines.
$graph->grid->SetLineStyle('dashed');
$graph->grid->SetColor('navy@0.5');
$graph->grid->Show();

$graph->ShowMinorTickMarks();

$graph->title->Set('Quality result');
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->SetTitles(array('One','Two','Three','Four','Five','Sex','Seven','Eight',
'Nine','Ten'));

$plot = new RadarPlot(array(12,35,20,30,33,15,37));
$plot->SetLegend('Goal');
$plot->SetColor('red','lightred');
$plot->SetFillColor('lightblue');
$plot->SetLineWeight(2);

$graph->Add($plot);
$graph->Stroke();

 

 

impulsex1.php

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_scatter.php');

$datay = array(20,22,12,13,17,20,16,19,30,31,40,43);

$graph = new Graph(300,200);
$graph->SetScale("textlin");

$graph->SetShadow();
$graph->img->SetMargin(40,40,40,40);		

$graph->title->Set("Simple mpuls plot");
$graph->title->SetFont(FF_FONT1,FS_BOLD);

$sp1 = new ScatterPlot($datay);
$sp1->mark->SetType(MARK_SQUARE);
$sp1->SetImpuls();

$graph->Add($sp1);
$graph->Stroke();

 

 

piec_csimex1.php

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_pie.php');

// Some data
$data = array(40,21,17,14,23);

// Create the Pie Graph. 
$graph = new PieGraph(300,200,'auto');
$graph->SetShadow();

// Set A title for the plot
$graph->title->Set("Client side image map");
$graph->title->SetFont(FF_FONT1,FS_BOLD);

// Create
$p1 = new PiePlot($data);
$p1->SetCenter(0.4,0.5);

$p1->SetLegends(array("Jan","Feb","Mar","Apr","May","Jun","Jul"));
$targ=array("pie_csimex1.php#1","pie_csimex1.php#2","pie_csimex1.php#3",
"pie_csimex1.php#4","pie_csimex1.php#5","pie_csimex1.php#6");
$alts=array("val=%d","val=%d","val=%d","val=%d","val=%d","val=%d");
$p1->SetCSIMTargets($targ,$alts);

$graph->Add($p1);


// Send back the HTML page which will call this script again
// to retrieve the image.
$graph->StrokeCSIM();

 

 

pielabelsex2.php

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_pie.php');

$data = array(19,12,4,3,3,12,3,3,5,6,7,8,8,1,7,2,2,4,6,8,21,23,2,2,12);

// Create the Pie Graph.
$graph = new PieGraph(300,350);

// Set A title for the plot
$graph->title->Set("Label guide lines");
$graph->title->SetFont(FF_VERDANA,FS_BOLD,12); 
$graph->title->SetColor("darkblue");
$graph->legend->Pos(0.1,0.2);


// Create pie plot
$p1 = new PiePlot($data);
$p1->SetCenter(0.5,0.55);
$p1->SetSize(0.3);

// Enable and set policy for guide-lines. Make labels line up vertically
$p1->SetGuideLines(true,false);
$p1->SetGuideLinesAdjust(1.5);

// Setup the labels
$p1->SetLabelType(PIE_VALUE_PER);	
$p1->value->Show();			
$p1->value->SetFont(FF_ARIAL,FS_NORMAL,9);	
$p1->value->SetFormat('%2.1f%%');		

// Add and stroke
$graph->Add($p1);
$graph->Stroke();

 

 

scatterlinkex1.php

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_scatter.php');

$datax = array(3.5,3.7,3,4,6.2,6,3.5,8,14,8,11.1,13.7);
$datay = array(20,22,12,13,17,20,16,19,30,31,40,43);
$graph = new Graph(300,200);
$graph->clearTheme();
$graph->img->SetMargin(40,40,40,40);
$graph->img->SetAntiAliasing();
$graph->SetScale("linlin");
$graph->SetShadow();
$graph->title->Set("Linked Scatter plot ex1");
$graph->title->SetFont(FF_FONT1,FS_BOLD);

$sp1 = new ScatterPlot($datay,$datax);
$sp1->SetLinkPoints(true,"red",2);
$sp1->mark->SetType(MARK_FILLEDCIRCLE);
$sp1->mark->SetFillColor("navy");
$sp1->mark->SetWidth(3);

$graph->Add($sp1);
$graph->Stroke();

 

 

barcode_ex0.php

require_once ('jpgraph/jpgraph_barcode.php');

$encoder = BarcodeFactory::Create(ENCODING_CODE39);
$e = BackendFactory::Create(BACKEND_IMAGE,$encoder);
$e->Stroke('ABC123');

 

 

 

 

bar2scalesex1.php

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_bar.php');

$datay=array(20,30,50,80);
$datay2=array(430,645,223,690);
$datazero=array(0,0,0,0);

// Create the graph. 
$graph = new Graph(450,200);
$graph->title->Set('Example with 2 scale bars');

// Setup Y and Y2 scales with some "grace"	
$graph->SetScale("textlin");
$graph->SetY2Scale("lin");
$graph->yaxis->scale->SetGrace(30);
$graph->y2axis->scale->SetGrace(30);

//$graph->ygrid->Show(true,true);
$graph->ygrid->SetColor('gray','lightgray@0.5');

// Setup graph colors
$graph->SetMarginColor('white');
$graph->y2axis->SetColor('darkred');


// Create the "dummy" 0 bplot
$bplotzero = new BarPlot($datazero);

// Create the "Y" axis group
$ybplot1 = new BarPlot($datay);
$ybplot1->value->Show();
$ybplot = new GroupBarPlot(array($ybplot1,$bplotzero));

// Create the "Y2" axis group
$ybplot2 = new BarPlot($datay2);
$ybplot2->value->Show();
$ybplot2->value->SetColor('darkred');
$ybplot2->SetFillColor('darkred');
$y2bplot = new GroupBarPlot(array($bplotzero,$ybplot2));

// Add the grouped bar plots to the graph
$graph->Add($ybplot);
$graph->AddY2($y2bplot);

// .. and finally stroke the image back to browser
$graph->Stroke();

 

 

bartutex1.php

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_bar.php');

// Some data
$databary=array(12,7,16,5,7,14,9,3);

// New graph with a drop shadow
$graph = new Graph(300,200);
$graph->SetShadow();

// Use a "text" X-scale
$graph->SetScale("textlin");

// Set title and subtitle
$graph->title->Set("Elementary barplot with a text scale");

// Use built in font
$graph->title->SetFont(FF_FONT1,FS_BOLD);

// Create the bar plot
$b1 = new BarPlot($databary);
$b1->SetLegend("Temperature");
//$b1->SetAbsWidth(6);
//$b1->SetShadow();

// The order the plots are added determines who's ontop
$graph->Add($b1);

// Finally output the  image
$graph->Stroke();

 

 

barline_csimex1.php

require_once ('jpgraph/jpgraph.php'); 
require_once ('jpgraph/jpgraph_line.php'); 
require_once ('jpgraph/jpgraph_bar.php'); 

$ydata = array(2,3,4,5,6,7,8,9,10,11); 
$ydata2 = array(1,2,3,4,5,6,7,8,9,10); 
$targ = array("#1","#2","#3","#4","#5","#6","#7","#8","#9","#10");
$alt = array(1,2,3,4,5,6,7,8,9,10); 

// Create the graph. 
$graph = new Graph(300,200);     
$graph->SetScale("textlin"); 
$graph->img->SetMargin(40,20,30,40); 
$graph->title->Set("CSIM example with bar and line"); 
$graph->title->SetFont(FF_FONT1,FS_BOLD);

// Setup axis titles
$graph->xaxis->title->Set("X-title"); 
$graph->yaxis->title->Set("Y-title"); 

// Create the linear plot 
$lineplot=new LinePlot($ydata); 
$lineplot->mark->SetType(MARK_FILLEDCIRCLE);
$lineplot->mark->SetWidth(5);
$lineplot->mark->SetColor('black');
$lineplot->mark->SetFillColor('red');
$lineplot->SetCSIMTargets($targ,$alt);

// Create line plot
$barplot=new barPlot($ydata2); 
$barplot->SetCSIMTargets($targ,$alt);

// Add the plots to the graph 
$graph->Add($lineplot); 
$graph->Add($barplot); 

$graph->StrokeCSIM();

 

 

bar_csimex2.php

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_bar.php');

$data1y=array(12,8,19,3,10,5);
$data2y=array(8,2,12,7,14,4);

// Create the graph. These two calls are always required
$graph = new Graph(310,200,'auto');
$graph->SetScale("textlin");
$graph->img->SetMargin(40,30,20,40);
$graph->SetShadow();

// Create the bar plots
$b1plot = new BarPlot($data1y);
$b1plot->SetFillColor("orange");
$targ=array("bar_clsmex2.php#1","bar_clsmex2.php#2","bar_clsmex2.php#3",
"bar_clsmex2.php#4","bar_clsmex2.php#5","bar_clsmex2.php#6");
$alts=array("val=%d","val=%d","val=%d","val=%d","val=%d","val=%d");
$b1plot->SetCSIMTargets($targ,$alts);

$b2plot = new BarPlot($data2y);
$b2plot->SetFillColor("blue");
$targ=array("bar_clsmex2.php#7","bar_clsmex2.php#8","bar_clsmex2.php#9",
"bar_clsmex2.php#10","bar_clsmex2.php#11","bar_clsmex2.php#12");
$alts=array("val=%d","val=%d","val=%d","val=%d","val=%d","val=%d");
$b2plot->SetCSIMTargets($targ,$alts);

// Create the grouped bar plot
$abplot = new AccBarPlot(array($b1plot,$b2plot));

$abplot->SetShadow();
$abplot->value->Show();

// ...and add it to the graPH
$graph->Add($abplot);

$graph->title->Set("Image map barex2");
$graph->xaxis->title->Set("X-title");
$graph->yaxis->title->Set("Y-title");

$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);


// Send back the HTML page which will call this script again
// to retrieve the image.
$graph->StrokeCSIM();

 

 

bartutex12.php

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_bar.php');

// Some data
$databary=array(12,7,16,6,7,14,9,3);
$months=$gDateLocale->GetShortMonth();

// New graph with a drop shadow
$graph = new Graph(300,200,'auto');
$graph->SetShadow();

// Use a "text" X-scale
$graph->SetScale("textlin");

// Specify X-labels
$graph->xaxis->SetTickLabels($months);

// Set title and subtitle
$graph->title->Set("Textscale with specified labels");

// Use built in font
$graph->title->SetFont(FF_FONT1,FS_BOLD);

// Create the bar plot
$b1 = new BarPlot($databary);
$b1->SetLegend("Temperature");

//$b1->SetAbsWidth(6);
//$b1->SetShadow();

// The order the plots are added determines who's ontop
$graph->Add($b1);

// Finally output the  image
$graph->Stroke();