require_once 'phplot.php'; $np = $tp['nlines']; $data = array(); for ($i = 1; $i <= 20; $i++) { $row = array('', $i); for ($j = 1; $j <= $np; $j++) { $row[] = $i + $j; } $data[] = $row; } $p = new PHPlot(800, 600); $p->SetTitle($tp['title'] . $tp['suffix']); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotAreaWorld(0, 0, 21, 40); $p->SetXTickIncrement(1); $p->SetYTickIncrement(5); # Options: if (isset($tp['LWidths'])) { $p->SetLineWidths($tp['LWidths']); } if (isset($tp['DStyle'])) { $p->SetDefaultDashedStyle($tp['DStyle']); } if (isset($tp['LStyles'])) { $p->SetLineStyles($tp['LStyles']); } $p->SetDrawXGrid(False); $p->SetDrawYGrid(False); $p->SetPlotType('lines'); $p->DrawGraph();
# Reload data colors and apply alpha to all: if (isset($tp['alpha'])) { $p->SetDataColors(NULL, NULL, $tp['alpha']); $title[] = "Alpha=" . $tp['alpha']; } $p->SetFileFormat($tp['output']); $title[] = strtoupper($tp['output']) . ' Output'; if ($tp['antialias']) { $title[] = "Antialiased"; } if ($tp['noalphablend']) { $title[] = "No alpha blending"; } if (isset($tp['gamma'])) { $title[] = "Gamma=" . $tp['gamma']; } if ($tp['savealpha']) { $title[] = "Save alpha"; } $p->SetTitle(implode(', ', $title)); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetLineWidths(3); $p->SetLineStyles('solid'); $p->SetPlotType('lines'); $p->SetXTickIncrement(1); $p->SetYTickIncrement(1); $p->SetDrawDashedGrid(False); // Or it doesn't show with anti-aliasing $p->SetDrawXGrid(True); $p->DrawGraph();
# Testing phplot - "Typical" plot with lots of elements, for manual require_once 'phplot.php'; $data = array(array('', -4, -64, 16, 40), array('', -3, -27, 9, 30), array('', -2, -8, 4, 20), array('', -1, -1, 1, 10), array('', 0, 0, 0, 0), array('', 1, 1, 1, -10), array('', 2, 8, 4, -20), array('', 3, 27, 9, -30), array('', 4, 64, 16, -40)); # Size of plot is set by PDF 72dpi resolution: $p = new PHPlot(400, 300); $p->SetDataType('data-data'); $p->SetDataValues($data); # Titles: $p->SetTitle('A Plot Containing Some Lines'); $p->SetXTitle('Independent Variable'); $p->SetYTitle('Dependent Variable'); # We don't use the data labels (all set to '') so might as well turn them off: $p->SetXDataLabelPos('none'); # Need to set area and ticks to get reasonable choices. $p->SetPlotAreaWorld(-4, -70, 4, 80); $p->SetXTickIncrement(1); $p->SetYTickIncrement(10); # Don't use dashes for 3rd line: $p->SetLineStyles(array('solid', 'dashed', 'solid')); # Make the lines thicker: $p->SetLineWidths(2); # Image border: $p->SetImageBorderType('raised'); $p->SetImageBorderColor('blue'); # Draw both grids: $p->SetDrawXGrid(True); $p->SetDrawYGrid(True); # And a legend: $p->SetLegend(array('x^3', 'x^2', '-10x')); $p->SetPlotType('lines'); $p->DrawGraph();
<?php # PHPlot Example: squared plot require_once 'phplot.php'; # To get repeatable results with 'random' data: mt_srand(1); # Make some noisy data: $data = array(); for ($i = 0; $i < 100; $i++) { $data[] = array('', $i / 4.0 + 2.0 + mt_rand(-20, 20) / 10.0); } $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); $plot->SetPlotType('squared'); $plot->SetDataType('text-data'); $plot->SetDataValues($data); $plot->SetTitle('Noisy Data (squared plot)'); # Make the lines a bit wider: $plot->SetLineWidths(2); # Turn on the X grid (Y grid is on by default): $plot->SetDrawXGrid(True); # Use exactly this data range: $plot->SetPlotAreaWorld(0, 0, 100, 40); $plot->DrawGraph();
<?php # PHPlot example - horizontal thinbarline plot (impulse plot) require_once 'phplot.php'; $data = array(array('', 79, 33.18), array('', 13, 22.62), array('', 71, 41.18), array('', 8, 14.72), array('', 48, 49.92), array('', 46, 49.68), array('', 90, 18.0), array('', 15, 25.5), array('', 73, 39.42), array('', 30, 42.0), array('', 24, 36.48), array('', 85, 25.5), array('', 14, 24.08), array('', 3, 5.82), array('', 98, 3.92), array('', 39, 47.58), array('', 70, 42.0), array('', 16, 26.88), array('', 81, 30.78), array('', 40, 48.0), array('', 44, 49.28)); $plot = new PHPlot(800, 400); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetUseTTF(True); $plot->SetTitle('Experimental Results'); $plot->SetXTitle('Density (g/cm³)'); // 179=superscript 3 $plot->SetYTitle('Temperature (°C)'); // 176=degrees $plot->SetPlotType('thinbarline'); $plot->SetDataType('data-data-yx'); $plot->SetDataValues($data); $plot->SetPlotAreaWorld(0, 0, 50, 100); $plot->SetLineWidths(4); $plot->DrawGraph();
# $data_colors = color array for SetDataColors() # $line_widths = line widths array for SetLineWidths() # $subtitle = Text below the main title # $point_shape and $point_size (single values) for outliers. require_once 'phplot.php'; if (empty($subtitle)) { $subtitle = 'Baseline'; } $data = array(array("No\nOutliers", 20, 22, 25, 30, 35), array("1\nOutlier", 30, 32, 35, 40, 45, 5), array("2\nOutliers", 40, 42, 45, 50, 55, 10, 60), array("3\nOutliers", 10, 20, 30, 40, 50, 9, 8, 52), array("4\nOutliers", 10, 20, 30, 40, 50, 4, 7, 80, 70), array("1 val\nAAAAA", 50, 50, 50, 50, 50), array("2 val\nAAAAB", 40, 40, 40, 40, 60), array("2 val\nAAABB", 40, 40, 40, 60, 60), array("2 val\nAABBB", 40, 40, 60, 60, 60), array("2 val\nABBBB", 40, 60, 60, 60, 60), array("3 val\nAAABC", 50, 50, 50, 60, 70), array("3 val\nAABBC", 20, 20, 50, 50, 70), array("3 val\nAABCC", 20, 20, 50, 70, 70), array("3 val\nABBBC", 20, 50, 50, 50, 70), array("3 val\nABBCC", 20, 50, 50, 70, 70), array("3 val\nABCCC", 20, 30, 50, 50, 50), array("4 val\nAABCD", 30, 30, 50, 60, 70), array("4 val\nABBCD", 30, 50, 50, 60, 70), array("4 val\nABCCD", 30, 40, 50, 50, 70), array("4 val\nABCDD", 30, 40, 50, 70, 70)); $p = new PHPlot(900, 600); $p->SetTitle("Box Plot with Various Data Cases\n{$subtitle}"); $p->SetDataType('text-data'); $p->SetDataValues($data); $p->SetPlotAreaWorld(NULL, 0, NULL, 100); $p->SetDrawYGrid(False); $p->SetPlotType('boxes'); $p->SetXTickPos('none'); # Optional style controls: if (isset($data_colors)) { $p->SetDataColors($data_colors); } if (isset($line_widths)) { $p->SetLineWidths($line_widths); } if (isset($point_shape)) { $p->SetPointShapes($point_shape); } if (isset($point_size)) { $p->SetPointSize($point_size); } $p->DrawGraph();
function graficarDemandaPronosticoError($oData) { $sql = "select\r\n\t\t\t\tdate_format(c1.fecha_fin, '%d/%m/%Y') fecha_fin, \r\n\t\t\t\tcantidad_demandada, \r\n\t\t\t\tprediccion, \r\n\t\t\t\terror,\r\n\t\t\t\tsenial \r\n\t\t\t\tfrom (\r\n\t\t\t\t\tselect\r\n\t\t\t\t\tfecha_fin, \r\n\t\t\t\t\tcantidad_demandada, \r\n\t\t\t\t\tprediccion, \r\n\t\t\t\t\terror, \r\n\t\t\t\t\tsenial \r\n\t\t\t\t\tfrom predicciones t1 \r\n\t\t\t\t\tinner join periodos t2 on t1.id_periodo = t2.id_periodo \r\n\t\t\t\t\twhere id_producto= " . $oData["id_producto"] . " \r\n\t\t\t\t\torder by fecha_fin asc) c1"; $rs = getRS($sql); $data = array(); $nro = getNrosRows($rs); $flag = 1; if ($nro) { while ($row = getRow($rs)) { if ($flag) { $inicio = $row['fecha_fin']; $flag = 0; } $nro--; if ($nro == 0) { $fin = $row['fecha_fin']; } $data[] = array('', $row['cantidad_demandada'], $row['prediccion'], $row['error'], $row['senial']); } } $plot = new PHPlot(800, 465); //$plot->SetImageBorderType('plain'); $plot->SetPlotType('lines'); //tipo de gráfico $plot->SetDataType('text-data'); $plot->SetDataValues($data); $plot->SetTitle('Demanda real, predicción, error y señal de rastreo. Periodo ' . $inicio . ' al ' . $fin); //Título $plot->SetLegend(array('Demanda real', 'Pronóstico', 'Error', 'Señal de rastreo')); //Referencia $plot->SetLineWidths(2); //ancho de la linea $plot->SetLineStyles("solid"); //estilo de la linea $plot->SetDataColors(array('green', 'blue', 'red', 'purple')); $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); # Draw both grids: $plot->SetDrawXGrid(True); $plot->SetDrawYGrid(True); $plot->DrawGraph(); }
<?php # PHPlot Example - Box Plot with outliers and line styles require_once 'phplot.php'; # Data array: each row is (label, X, Ymin, YQ1, Ymid, YQ3, Ymax, [Youtlier...]) $data = array(array('', 1, 10, 15, 20, 25, 30), array('', 2, 12, 14, 18, 20, 24, 6, 8, 28), array('', 3, 5, 11, 19, 28, 35), array('', 4, 14, 17, 21, 26, 28, 9, 12, 35, 32), array('', 5, 12, 15, 22, 27, 30), array('', 6, 15, 18, 20, 22, 26, 12), array('', 7, 10, 15, 21, 26, 28, 32), array('', 8, 11, 15, 20, 24, 27, 6, 8), array('', 9, 10, 15, 19, 22, 26, 4, 34)); $plot = new PHPlot(800, 600); $plot->SetTitle('Box Plot with outliers and styles'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetPlotType('boxes'); $plot->SetImageBorderType('plain'); // Improves presentation in the manual # Use dashed lines for the upper and lower whiskers: $plot->SetLineStyles('dashed'); # Make the box and belt use a thicker line: $plot->SetLineWidths(array(3, 3, 1)); # Make the outliers red, and everything else blue: $plot->SetDataColors(array('blue', 'blue', 'red', 'blue')); # Draw the outliers using a "star": $plot->SetPointShapes('star'); $plot->DrawGraph();
} } } else { for ($j = 0; $j < $ny; $j++) { $widths[$j] = $j + 1; } } } if ($set_styles) { // $p->SetDefaultDashedStyle('10-5'); $p->SetDrawYGrid(False); // Hard to see dashed lines with dashed grid. } // Always do SetLineStyles (if set_styles is false, it sets them all to solid) $p->SetLineStyles($styles); if ($set_linewidths) { $p->SetLineWidths($widths); } $p->SetLegend($legend); $p->SetLegendPosition(0, 0, 'plot', 0, 0, 5, 5); if ($legend_use_shapes) { $p->SetLegendUseShapes(True); } $p->SetPlotBgColor('black'); if ($plot_area_background) { $p->SetDrawPlotAreaBackground(True); } if (isset($colorbox_width)) { $p->legend_colorbox_width = $colorbox_width; } $p->DrawGraph();
<?php # $Id$ # Testing phplot - OHLC - all up/down combos - candlesticks if (empty($plot_type)) { $plot_type = 'candlesticks'; } require_once 'phplot.php'; /* Testing all cases as follows. There are 16 combinations but 4 duplicates L = Low, O = Open, C = Close, H = High. Data order: Open, High, Low, Close */ $data = array(array('L < O < C < H', 2, 4, 1, 3), array('L < O < C = H', 2, 3, 1, 3), array('L < O = C < H', 2, 3, 1, 2), array('L < O = C = H', 2, 2, 1, 2), array('L = O < C < H', 1, 3, 1, 2), array('L = O < C = H', 1, 2, 1, 2), array('L = O = C < H', 1, 2, 1, 1), array('L = O = C = H', 1, 1, 1, 1), array('L < C < O < H', 3, 4, 1, 2), array('L < C < O = H', 3, 3, 1, 2), array('L < C = O < H', 2, 3, 1, 2), array('L < C = O = H', 2, 2, 1, 2), array('L = C < O < H', 2, 3, 1, 1), array('L = C < O = H', 2, 2, 1, 1), array('L = C = O < H', 1, 2, 1, 1), array('L = C = O = H', 1, 1, 1, 1)); $p = new PHPlot(800, 600); $p->SetTitle("OHLC Plots, All Data Order Cases\nPlot type: {$plot_type}"); $p->SetDataType('text-data'); $p->SetDataValues($data); $p->SetPlotType($plot_type); $p->SetXTickPos('none'); $p->SetXDataLabelAngle(90); $p->SetPlotAreaWorld(NULL, 0, NULL, 5); $p->SetDrawYGrid(False); $p->SetLineWidths(array(2, 3)); $p->DrawGraph();
$graph->SetDataType("data-data-error"); //Must be called before SetDataValues $graph->SetNewPlotAreaPixels(90, 40, 540, 190); $graph->SetDataValues($example_data); $graph->SetXLabelType("time"); $graph->SetXLabelAngle(90); $graph->SetXTitle(""); $graph->SetYTitle("Price"); $graph->SetYTickIncrement(20); $graph->SetXTickIncrement(2679000); $graph->SetXTimeFormat("%b %y"); $graph->SetPlotType("lines"); $graph->SetErrorBarShape("line"); $graph->SetPointShape("halfline"); $graph->SetYScaleType("log"); $graph->SetLineWidths(array(1)); $graph->SetPlotAreaWorld(883634400, 1, 915095000, 140); $graph->SetXDataLabelPos('none'); $graph->DrawGraph(); //Now do the second chart on the image unset($example_data); $graph->SetYScaleType("linear"); include "./data_date.php"; $graph->SetDataType("data-data"); //Must be called before SetDataValues $graph->SetDataValues($example_data); $graph->SetNewPlotAreaPixels(90, 260, 540, 350); $graph->SetDataValues($example_data); $graph->SetXLabelType("time"); $graph->SetXLabelAngle(90); $graph->SetXTitle("");
<?php # PHPlot Example: thinbarline plot, wider require_once 'phplot.php'; # To get repeatable results with 'random' data: mt_srand(1); # Make some noisy data: $data = array(); for ($i = 0; $i < 100; $i++) { $data[] = array('', $i / 4.0 + 2.0 + mt_rand(-20, 20) / 10.0); } $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); $plot->SetPlotType('thinbarline'); $plot->SetDataType('text-data'); $plot->SetDataValues($data); # Main plot title: $plot->SetTitle('Noisy Data (thinbarline, wider)'); # Make the lines wider: $plot->SetLineWidths(3); $plot->DrawGraph();
<?php # $Id$ # PHPlot Example: thinbarline plot # This is a parameterized test. Other scripts can set $tp and then include # this script. The parameters are shown in the defaults array below: if (!isset($tp)) { $tp = array(); } $tp = array_merge(array('title' => 'Noisy random data (thinbarline)', 'suffix' => "", 'LWidth' => NULL), $tp); require_once 'phplot.php'; # To get a repeatable test with 'random' data: mt_srand(1); # Make some noisy data: $data = array(); for ($i = 0; $i < 100; $i++) { $data[] = array('', $i / 4.0 + 2.0 + mt_rand(-20, 20) / 10.0); } $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); $plot->SetPlotType('thinbarline'); $plot->SetDataType('text-data'); $plot->SetDataValues($data); # Main plot title: $plot->SetTitle($tp['title'] . $tp['suffix']); # Options: if (isset($tp['LWidth'])) { $plot->SetLineWidths($tp['LWidth']); } $plot->DrawGraph();