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(); }
function testBars() { # PHPlot Example: Bar chart, 3 data sets, unshaded $data = array(array('Jan', 40, 2, 4), array('Feb', 30, 3, 4), array('Mar', 20, 4, 4), array('Apr', 10, 5, 4), array('May', 3, 6, 4), array('Jun', 7, 7, 4), array('Jul', 10, 8, 4), array('Aug', 15, 9, 4), array('Sep', 20, 5, 4), array('Oct', 18, 4, 4), array('Nov', 16, 7, 4), array('Dec', 14, 3, 4)); $plot = new PHPlot(800, 600); $plot->SetIsInline(true); $plot->SetImageBorderType('plain'); $plot->SetPlotType('bars'); $plot->SetDataType('text-data'); $plot->SetDataValues($data); # Main plot title: $plot->SetTitle('Unshaded Bar Chart with 3 Data Sets'); # No 3-D shading of the bars: $plot->SetShading(0); # Make a legend for the 3 data sets plotted: $plot->SetLegend(array('Engineering', 'Manufacturing', 'Administration')); # Turn off X tick labels and ticks because they don't apply here: $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); $plot->DrawGraph(); }
# PHPlot Example - Horizontal Error Plot require_once 'phplot.php'; # The experimental results as a series of temperature measurements: $results = array(98, 102, 100, 103, 101, 105, 110, 108, 109); # The accuracy of our measuring equipment is +/- 5% $error_factor = 0.05; # Convert the experimental results to a PHPlot data array for error plots. function reduce_data($results, $error_factor) { # Use the average of measurements to approximate the error amount: $err = $error_factor * array_sum($results) / count($results); # Build the 'data-data-yx-error' data array: $data = array(); $i = 1; foreach ($results as $value) { $data[] = array("Sample {$i}", $i++, $value, $err, $err); } return $data; } $plot = new PHPlot(800, 600); $plot->SetTitle('Experiment Results'); $plot->SetXTitle('Melting Temperature (degrees C)'); $plot->SetDataValues(reduce_data($results, $error_factor)); $plot->SetDataType('data-data-yx-error'); $plot->SetPlotType('points'); $plot->SetYTickPos('none'); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetPlotAreaWorld(80); $plot->DrawGraph();
function plotfile_me($pdf, $mv_id, $w = 800, $h = 600) { $mvs = new mietvertraege(); $mvs->get_mietvertrag_infos_aktuell($mv_id); $mk = new mietkonto(); $datum_mietdefinition = $mk->datum_1_mietdefinition($mv_id); // echo "<h1>$datum_mietdefinition</h1>"; $a_dat = explode('-', $datum_mietdefinition); $jahr_a = date("Y") - 2; $jahr_e = date("Y") + 3; $jahre = $jahr_e - $jahr_a; $z = 0; for ($jahr = $jahr_a; $jahr <= $jahr_e; $jahr++) { $monat = date("m"); $mk->kaltmiete_monatlich($mv_id, $monat, $jahr); if ($jahr > $jahr_a) { $miete_vorjahr = $arr_stat[$z - 1][1]; $prozent = ($mk->ausgangs_kaltmiete - $miete_vorjahr) / ($miete_vorjahr / 100); } else { $prozent = 0; } $prozent = nummer_punkt2komma($prozent); $arr_stat[$z][0] = "{$jahr}\n{$mk->ausgangs_kaltmiete}\nEUR\n{$prozent} %"; $arr_stat[$z][1] = $mk->ausgangs_kaltmiete; $z++; } // print_r($arr_stat); require_once 'phplot.php'; $plot = new PHPlot($w, $h); $plot->SetImageBorderType('plain'); $plot->SetPlotType('bars'); $plot->SetDataType('text-data'); $plot->SetDataValues($arr_stat); // Main plot title: $plot->SetTitle('MIETENTWICKLUNG' . " {$mvs->einheit_kurzname} \n {$mvs->personen_name_string}"); // No 3-D shading of the bars: $plot->SetShading(0); // Make a legend for the 3 data sets plotted: // $plot->SetLegend(array('Mieteinnahmen', 'Leerstand')); $plot->SetLegend(array('MIETE')); // Turn off X tick labels and ticks because they don't apply here: $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); // Draw it $plot->SetIsInline(true); $img = $plot->DrawGraph(); $px = 'px'; // echo "<hr>$plot->img "; // $plot->PrintImageFrame(); // $hhh = $plot->PrintImage(); $ima = $plot->EncodeImage(); // echo "<a style=\"width:$w$px;heigth:$h$px;\" href=\"?option=stat_mv_big&mv_id=$mv_id\"><img style=\"width:$w$px;heigth:$h$px;\" src=\"$plot->img\"></img></a>"; // die(); // echo "<img src=\"$ima\">"; // die(); if ($mvs->mietvertrag_aktuell == 1) { $pdf->ezNewPage(); $druckdatum = date("d.m.Y"); $pdf->addText(464, 730, 7, "<b>Druckdatum: {$druckdatum}</b>"); $pdf->addPngFromFile($ima, $pdf->x + 10, $pdf->y - $h, $w, $h); } }
# 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();
$title = "Test Attribute Resets:\n"; if (empty($test_resets)) { $title .= 'Baseline - red border, formatted labels'; } else { $title .= 'Reset to no border, no label formatting'; } $plot = new PHPlot(400, 400); $plot->SetTitle($title); $plot->SetPlotType('lines'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetPlotAreaWorld(-1000, 0); $plot->SetXDataLabelPos('none'); $plot->SetXTickIncrement(500); $plot->SetXLabelType('data', 0, '', 'M'); $plot->SetYTickIncrement(200000); $plot->SetYLabelType('data', 2); $plot->SetImageBorderType('raised'); $plot->SetImageBorderColor('red'); $plot->SetDrawXGrid(False); $plot->SetDrawYGrid(False); # Set $test_resets=True and include this file to test resets: if (!empty($test_resets)) { # Reset to no border: $plot->SetImageBorderType('none'); # Reset X to no formatting using empty string: $plot->SetXLabelType(''); # Reset Y to no formatting using no argument: $plot->SetYLabelType(); } $plot->DrawGraph();
function guifi_stats_chart06() { include drupal_get_path('module', 'guifi') . '/contrib/phplot/phplot.php'; $gDirTTFfonts = drupal_get_path('module', 'guifi') . '/contrib/fonts/'; if (isset($_GET['width'])) { $gwidth = $_GET['width']; } else { $gwidth = 500; } if (isset($_GET['height'])) { $gheight = $_GET['height']; } else { $gheight = 450; } $today = getdate(); $year = $today[year]; $month = $today[mon]; $month = $month - 12; $n = 0; $tot = 0; if ($month < 1) { $year = $year - 1; $month = 12 + $month; } $datemin = mktime(0, 0, 0, $month, 1, $year); if (isset($_GET['zone'])) { $zone_id = $_GET['zone']; if ($zone_id == "0") { $zone_id = "3671"; } } else { $zone_id = "3671"; } $azone = array(); $avalue = array(); $azone[$zone_id] = array($zone_id); $achilds = array_keys(guifi_zone_childs_tree($zone_id, 1)); foreach ($achilds as $key => $child) { if ($child != $zone_id) { $azone[$child] = array(); $avalue[$child] = 0; $aschilds = guifi_zone_childs($child); foreach ($aschilds as $skey => $schild) { array_push($azone[$child], $schild); } } } $vsql = "select COUNT(*) as num, zone_id\n from {guifi_location}\n where timestamp_created >= " . $datemin . " and status_flag='Working' "; if ($zone_id != "0") { $achilds = guifi_zone_childs($zone_id); $v = ""; foreach ($achilds as $key => $child) { if ($v == "") { $v .= "zone_id=" . $child; } else { $v .= " or zone_id=" . $child; } } $vsql .= "AND (" . $v . ") "; } $vsql .= "GROUP BY zone_id "; $result = db_query($vsql); while ($record = db_fetch_object($result)) { foreach ($azone as $key => $grupzone) { if (in_array($record->zone_id, $grupzone)) { $avalue[$key] = $avalue[$key] + $record->num; } } } foreach ($avalue as $key => $value) { if ($value != 0) { $data[] = array(guifi_get_zone_name($key), $value); $tot = $tot + $value; } } $shapes = array('none'); $plot = new PHPlot($gwidth, $gheight); $plot->SetPlotAreaWorld(0, 0, NULL, NULL); $plot->SetImageBorderType('plain'); $plot->SetFileFormat('png'); $plot->SetPlotType("pie"); $plot->SetDataType("text-data-single"); $plot->SetDataValues($data); $plot->SetDataColors(array('red', 'green', 'blue', 'yellow', 'cyan', 'magenta', 'brown', 'lavender', 'pink', 'gray', 'orange')); $plot->SetTTFPath($gDirTTFfonts); $plot->SetFontTTF('title', 'Vera.ttf', 12); $plot->SetFontTTF('legend', 'Vera.ttf', 7); if (isset($_GET['title'])) { $plot->SetTitle("guifi.net \n" . t($_GET['title'])); } else { if ($zone_id == "0") { $plot->SetTitle("guifi.net \n" . t('Last year')); } else { $plot->SetTitle("guifi.net \n" . t('zone') . ": " . guifi_get_zone_name($zone_id) . "\n" . t('Last year')); } } $plot->SetShading(1); $plot->SetLabelScalePosition(0.45); $plot->SetLegendStyle("left", "left"); $plot->SetLegendPixels(0, 0); foreach ($data as $row) { $plot->SetLegend(implode(': ', $row)); } $plot->SetIsInline(TRUE); $plot->DrawGraph(); }
$bardata = array(); $cumulateddata = array(); $max = 1; foreach ($stats->getTimestats($term, $REX['ADDON']['rexsearch_plugins'][$parent][$mypage]['settings']['searchtermselectmonthcount']) as $month) { $bardata[] = array(date('M', mktime(0, 0, 0, $month['m'], 1, 2010)) . "\n" . $month['count'], $month['count']); if ($month['count'] > $max) { $max = $month['count']; } } $title = $I18N->Msg('a587_stats_searchterm_timestats_title', empty($term) ? $I18N->Msg('a587_stats_searchterm_timestats_title0_all') : $I18N->Msg('a587_stats_searchterm_timestats_title0_single', $term), intval($_GET['monthcount'])); if (rex_lang_is_utf8()) { $title = utf8_decode($title); } // draw bars $plot = new PHPlot(700, 240); $plot->SetImageBorderType('none'); $plot->SetTransparentColor('white'); $plot->SetMarginsPixels(NULL, NULL, 26, NULL); # Make sure Y axis starts at 0: $plot->SetPlotAreaWorld(NULL, 0, NULL, NULL); $len = strlen('' . $max); $plot->SetYTickIncrement(max(1, ceil($max / pow(10, $len - 1)) * pow(10, $len - 2))); # Main plot title: $plot->SetTitle($title); $plot->SetFont('title', 3); // draw bars $plot->SetPlotType('bars'); $plot->SetDataType('text-data'); $plot->SetDataValues($bardata); $plot->SetDataColors(array('#14568a', '#2c8ce0', '#dfe9e9')); $plot->SetShading(ceil(48 / $REX['ADDON']['rexsearch_plugins'][$parent][$mypage]['settings']['searchtermselectmonthcount']));
} // Avoid cumulative round-off error $data[] = array('', $i - 1, $y); $y += $dy; } # Base setup for all 4 sub-plots: $plot = new PHPlot(800, 400); $plot->SetTitle("PHPlot Auto-range Illustration\n" . "Case ({$case}) Y data range {$ymin} to {$ymax}"); $plot->SetDataType($data_type); $plot->SetDataValues($data); $plot->SetPlotType($plotlot_type); $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); $plot->SetXDataLabelPos('none'); $plot->SetPrintImage(False); $plot->SetImageBorderType('solid'); # Sub-plot area limits for Y (in pixels): $py1 = 55; $py2 = 355; # Pixel limits for X: $pdx = 195; // Approx plot_width / 4 sub-plots $px_l = 40; // Left offset $px_r = 5; // Right inset # Sub-plot (1) shows the initial plot range = date range. $plot->SetPlotAreaPixels($px_l, $py1, $pdx - $px_r, $py2); $plot->SetXTitle('(1) Initial Range'); # Disable zero magnet and range adjustment: $plot->TuneYAutoRange(0, 'R', 0);
} else { $title .= $tp['ibwidth']; } $p->SetTitle($title); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetDrawXGrid(False); $p->SetDrawYGrid(False); if (!empty($tp['plotborder'])) { $p->SetPlotBorderType($tp['plotborder']); } if (!empty($tp['pbcolor'])) { $p->SetGridColor($tp['pbcolor']); } if (!empty($tp['imageborder'])) { $p->SetImageBorderType($tp['imageborder']); } if (!empty($tp['ibcolor'])) { $p->SetImageBorderColor($tp['ibcolor']); } if (!empty($tp['ibwidth'])) { $p->SetImageBorderWidth($tp['ibwidth']); } # Move Y axis in so affect of plot area borders is more visible: $p->SetYAxisPosition(0); # Turn on all side labels, ticks, titles: $p->SetXTickLabelPos('both'); $p->SetXTickPos('both'); $p->SetYTickLabelPos('both'); $p->SetYTickPos('both'); $p->SetPlotType('lines');
# Testing PHPlot: Bar charts # 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' => 'Bar Chart with 3 Data Sets', 'suffix' => "", 'IBType' => NULL, 'Shade' => NULL, 'DBColors' => NULL), $tp); require_once 'phplot.php'; $data = array(array('Jan', 40, 2, 4), array('Feb', 30, 3, 4), array('Mar', 20, 4, 4), array('Apr', 10, 5, 4), array('May', 3, 6, 4), array('Jun', 7, 7, 4), array('Jul', 10, 8, 4), array('Aug', 15, 9, 4), array('Sep', 20, 5, 4), array('Oct', 18, 4, 4), array('Nov', 16, 7, 4), array('Dec', 14, 3, 4)); $plot = new PHPlot(800, 600); $plot->SetPlotType('bars'); $plot->SetDataType('text-data'); $plot->SetDataValues($data); # Main plot title: $plot->SetTitle($tp['title'] . $tp['suffix']); # Make a legend for the 3 data sets plotted: $plot->SetLegend(array('Engineering', 'Manufacturing', 'Administration')); # Turn off X tick labels and ticks because they don't apply here: $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); # Options: if (isset($tp['IBType'])) { $plot->SetImageBorderType($tp['IBType']); } if (isset($tp['Shade'])) { $plot->SetShading($tp['Shade']); } if (isset($tp['DBColors'])) { $plot->SetDataBorderColors($tp['DBColors']); } $plot->DrawGraph();
function get_png($objekt_id, $monat, $jahr, $w = 300, $h = 200) { $monat = sprintf('%02d', $monat); include_once BERLUS_PATH . "/classes/phplot.php"; $plot = new PHPlot($w, $h, "/tmp/plot_sanierung.png"); $plot->SetImageBorderType('plain'); $plot->SetPlotType('stackedbars'); $plot->SetDataType('text-data'); // $column_names = array('LEER VM', 'LEER NEU', 'IST WM','DIFF'); $plot->SetShading(10); $plot->SetLegendReverse(True); // $plot->SetLegend($column_names); $oo = new objekt(); $oo->get_objekt_infos($objekt_id); $anz_einheiten_alle = $oo->anzahl_einheiten_objekt($objekt_id); $datum_heute = "{$jahr}-{$monat}-01"; $mi = new miete(); $datum_vormonat = $mi->tage_minus($datum_heute, 30); $arr = $this->leerstand_finden_monat($objekt_id, $datum_vormonat); $anz_leer_vormonat = count($arr); // unset($arr); $arr_leer = $this->leerstand_finden_monat($objekt_id, $datum_heute); $anz_leer_akt = count($arr_leer); $anz_vermietet = $anz_einheiten_alle - $anz_leer_akt; $leere = $this->array_intersect_recursive($arr_leer, $arr, 'EINHEIT_KURZNAME'); $vermietete = $this->array_intersect_recursive($arr, $arr_leer, 'EINHEIT_KURZNAME'); $leer_akt_string = ''; $anz__L = count($leere); if ($anz__L > 0) { for ($ee = 0; $ee < $anz__L; $ee++) { $leer_akt_string .= $leere[$ee] . "\n"; } } $vermietet_akt_string = ''; $anz__V = count($vermietete); // print_r($vermietete); if ($anz__V > 0) { for ($ee = 0; $ee < $anz__V; $ee++) { $vermietet_akt_string .= $vermietete[$ee] . "\n"; } } // unset($arr); /* * $mvs = new mietvertraege; * $anz_ausgezogene = $mvs->anzahl_ausgezogene_mieter($objekt_id, $jahr, $monat); * $anz_eingezogene = $mvs->anzahl_eingezogene_mieter($objekt_id, $jahr, $monat); */ $bilanz_akt = $anz__V - $anz__L; // 0-1 = -1; $z = 0; /* * $data[$z][] = "ALLE\nAKTUELL"; * $data[$z][] = $anz_einheiten_alle; * * $data[$z][] = 0; * $data[$z][] = 0; * */ // $z++; /* * $data[$z][] = "LEER\nVERM."; * $data[$z][] = 0; * $data[$z][] = $anz_vermietet; * $data[$z][] = $anz_leer_akt; */ $data[$z][] = "VOR-\nMONAT"; $data[$z][] = 0; $data[$z][] = $anz_leer_vormonat; $z++; $data[$z][] = "LEER-\nAKTUELL"; $data[$z][] = 0; $data[$z][] = 0; $data[$z][] = $anz_leer_akt; $z++; $data[$z][] = "LEER\n\n{$leer_akt_string}"; $data[$z][] = '0'; $data[$z][] = '0'; $data[$z][] = $anz__L; $z++; $data[$z][] = "VERM.\n\n{$vermietet_akt_string}"; $data[$z][] = '0'; $data[$z][] = $anz__V; $z++; $data[$z][] = "BILANZ\nEIN/AUS"; if ($bilanz_akt < 0) { $data[$z][] = 0; $data[$z][] = 0; $data[$z][] = 0; $data[$z][] = 0; $data[$z][] = $bilanz_akt; } else { $data[$z][] = 0; $data[$z][] = $bilanz_akt; } // $z++; $plot->SetYDataLabelPos('plotstack'); $plot->SetDataValues($data); // Main plot title: $plot->SetTitle("{$oo->objekt_kurzname} {$monat}/{$jahr}"); // No 3-D shading of the bars: $plot->SetShading(0); // Make a legend for the 3 data sets plotted: // $plot->SetLegend(array('Mieteinnahmen', 'Leerstand')); // $plot->SetLegend(array('MIETE')); // Turn off X tick labels and ticks because they don't apply here: $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); // Draw it $plot->SetIsInline(true); $plot->DrawGraph(); // echo "<hr>$plot->img "; // $plot->PrintImageFrame(); // $ima = $plot->PrintImage(); $ima = $plot->EncodeImage(); // ob_clean(); return $ima; // echo "<img src=\"$ima\"></img>"; }