function graficoBarra($data, $archivo = "", $meta_data = array('titulo' => 'Sin Título', 'tituloX' => 'Eje X', 'tituloY' => 'Eje Y', 'color' => 'SkyBlue', 'width' => 800, 'height' => 600, 'angle' => 45), $legend = array("Datos")) { # Objeto que crea el gráfico y su tama?o $plot = new PHPlot($meta_data['width'], $meta_data['height']); $plot->SetImageBorderType('plain'); # Setea el archivo donde se guarda la imagen generada y no permite la visualización inmediata $plot->SetPrintImage(false); $plot->SetFileFormat("jpg"); $plot->SetOutputFile($archivo); $plot->SetIsInline(true); # Envio de datos $plot->SetDataValues($data); # Tipo de gráfico y datos $plot->SetDataType("text-data"); $plot->SetPlotType("bars"); # Setiando el True type font //$plot->SetTTFPath(TTFPath); //$plot->SetUseTTF(TRUE); $plot->SetAxisFontSize(2); $plot->SetVertTickIncrement(7); //$plot->SetXTickLength(7); //$plot->SetDataColors($meta_data['color']); $plot->SetDataColors(array($meta_data['color'], 'red', 'white')); $plot->SetLegendPixels(1, 1); $plot->SetLegend($legend); # Etiquetas del eje Y: $plot->SetYTitle($meta_data['tituloY']); $plot->SetYDataLabelPos('plotin'); # Título principal del gráfico: $plot->SetTitle($meta_data['titulo']); # Etiquetas eje X: $plot->SetXTitle($meta_data['tituloX']); if (isset($meta_data['angle'])) { $plot->SetXLabelAngle($meta_data['angle']); } else { $plot->SetXLabelAngle(45); } $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); # Método que dibuja el gráfico $plot->DrawGraph(); $plot->PrintImage(); }
<?php //Include the code include "../phplot.php"; //Define the object and get background image 0cars.jpg //////NOTE! THIS EXAMPLE WILL ONLY WORK IF YOU HAVE //////JPEG SUPPORT ENABLED. (Use a different file as a background //////if you have png or gif enabled. $graph = new PHPlot(500, 223, "", "0cars.jpg"); //Set some data $example_data = array(array("55", 5), array("60", 10), array("65", 20), array("70", 30), array("75", 25), array("80", 10)); $graph->SetDataValues($example_data); //Set up some nice formatting things $graph->SetTitle("Speed Histogram"); $graph->SetXLabel("Miles per Hour"); $graph->SetYLabel("Percent of Cars"); $graph->SetVertTickIncrement(5); $graph->SetPlotAreaWorld(0, 0, 6, 35); //Make the margins nice for the background image $graph->SetMarginsPixels(80, 35, 35, 70); //Set up some color and printing options $graph->background_done = 1; //The image background we get from 0cars.jpg $graph->SetDrawPlotAreaBackground(0); //Plot Area background we get from the image $graph->SetDataColors(array("white"), array("black")); //Set Output format $graph->SetFileFormat("png"); //Draw it $graph->DrawGraph();
<?php include "./data_date2.php"; include "../phplot.php"; $graph = new PHPlot(600, 400); $graph->SetPrintImage(0); //Don't draw the image yet $graph->SetDataType("data-data-error"); //Must be called before SetDataValues $graph->SetNewPlotAreaPixels(90, 40, 540, 190); $graph->SetDataValues($example_data); $graph->SetXGridLabelType("time"); $graph->SetXDataLabelAngle(90); $graph->SetXLabel(""); $graph->SetYLabel("Price"); $graph->SetVertTickIncrement(20); $graph->SetHorizTickIncrement(2679000); $graph->SetXTimeFormat("%b %y"); $graph->SetPlotType("lines"); $graph->SetErrorBarShape("line"); $graph->SetPointShape("halfline"); $graph->SetYScaleType("log"); $graph->SetLineWidth(1); $graph->SetPlotAreaWorld(883634400, 1, 915095000, 140); $graph->DrawGraph(); //Now do the second chart on the image unset($example_data); $graph->SetPrintImage(1); //Now draw the image $graph->SetYScaleType("linear"); include "./data_date.php";
$graph = new PHPlot(500, 250); $graph->SetDataType('linear-linear'); //Specify some data $data = array(array('', 2000, 750), array('', 2010, 1700), array('', 2015, 2000), array('', 2020, 1800), array('', 2025, 1300), array('', 2030, 400)); $graph->SetDataValues($data); //Specify plotting area details $graph->SetPlotType('lines'); $graph->SetTitleFontSize('2'); $graph->SetTitle('Social Security trust fund asset estimates, in $ billions'); $graph->SetPlotAreaWorld(2000, 0, 2035, 2000); $graph->SetPlotBgColor('white'); $graph->SetPlotBorderType('left'); $graph->SetBackgroundColor('white'); $graph->SetDataColors(array('red'), array('black')); //Define the X axis $graph->SetXLabel('Year'); $graph->SetHorizTickIncrement('5'); $graph->SetXGridLabelType('default'); //Define the Y axis $graph->SetVertTickIncrement('500'); $graph->SetPrecisionY('0'); $graph->SetYGridLabelType('right'); $graph->SetLightGridColor('blue'); //Disable image output $graph->SetPrintImage(0); //Draw the graph $graph->DrawGraph(); //$pdf = new MEM_IMAGE(); //$pdf->AddPage(); //$pdf->GDImage($graph->PrintImage(),30,20,140); //$pdf->Output();
$b = $a * rand(0, 1) / 10; $c = $a * rand(0, 1) / 10; $data[] = array("{$label[$i]}", $i + 1, $a, $b, $c); } //Define the data for error bars $graph->SetDataType("linear-linear-error"); //Must be first thing //Set the Graph particulars $graph->SetPrecisionX(0); $graph->SetPrecisionY(0); $graph->SetUseTTF("0"); $graph->SetDrawYGrid("1"); // 1 = true $graph->SetDataValues($data); $graph->SetImageArea(600, 400); $graph->SetVertTickIncrement(""); $graph->SetHorizTickIncrement(1); $graph->SetErrorBarLineWidth(1); $graph->SetYScaleType("log"); $graph->SetPointShape("halfline"); $graph->SetErrorBarShape("line"); $graph->SetPlotType("points"); $graph->SetXGridLabelType("title"); $graph->SetXLabel("Day"); $graph->SetYLabel("index"); $graph->SetTitle("Stock Market Data"); //$graph->SetErrorBarColors(array("blue","red","green","black")); $graph->SetDataColors(array("blue", "green", "yellow", "red"), array("black")); //$graph->SetPlotAreaWorld(0,5,32,30); //$graph->SetPlotAreaPixels(150,50,600,400); /*
$c = rand(0, 1); $data[] = array("{$label[$i]}", $i + 1, $a, $b, $c); } $graph->SetDataType("linear-linear-error"); //Must be first thing $graph->SetPrecisionY(0); $graph->SetPrecisionX(0); //////////////////////////////////////////////// $graph->SetDataType($which_data_type); //Must be first thing $graph->SetUseTTF("0"); $graph->SetDrawYGrid("1"); // 1 = true $graph->SetDataValues($data); $graph->SetImageArea($XSIZE_in, $YSIZE_in); $graph->SetVertTickIncrement($which_vti); $graph->SetHorizTickIncrement($which_hti); $graph->SetLineWidth("1"); $graph->SetPointShape("{$which_dot}"); $graph->SetErrorBarShape("{$which_error_type}"); $graph->SetPlotType($which_plot_type); $graph->SetXLabel($xlbl); $graph->SetYLabel($ylbl); $graph->SetTitle($title); $graph->SetDataColors(array("blue", "green", "yellow", "red"), array("black")); if ($maxy_in) { $graph->SetPlotAreaWorld(0, $miny_in, count($data), $maxy_in); } //$graph->SetPlotAreaWorld(0,-5,count($data),30); //$graph->SetPlotAreaWorld(0,-10,5,35); //$graph->SetPlotAreaPixels(150,50,600,400);