$base_time = mktime(0, 0, 12, 6, 30, 2004); $interval = 60 * 60; $data = array(); # This is a quadratic from 0,0 to 50,20 to 100,0: for ($i = 0; $i <= 100; $i++) { if ($i % 24 == 0) { $t = $base_time + $i * $interval; } else { $t = ''; } $data[] = array($t, $i, $i * (0.8 - 0.008 * $i)); } $p = new PHPlot(800, 600); $p->SetTitle('Date X labels - 8 hour ticks, 24 hour labels'); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotAreaWorld(0, 0, 100, 20); $p->SetXLabelType('time'); # For example: # %Y-%m-%d 2004-12-31 # %b %Y Dec 2004 # %b %d, %Y Dec 31, 2004 # %d %b 31 Dec $p->SetXTimeFormat('%m/%d %H:%M'); # Turn off X tick labels, use our data labels only: $p->SetXTickLabelPos('none'); # But we can use the tick marks themselves if we make them line up right. $p->SetXTickIncrement(8); $p->SetDrawXGrid(True); $p->SetPlotType('lines'); $p->DrawGraph();
function make_plot($plot_type, $data_type, $nx, $ny) { $plot = new PHPlot(1280, 1024); $plot->SetPrintImage(False); $plot->SetFailureImage(False); $plot->SetDataType($data_type); $plot->SetDataValues(make_data_array($plot_type, $data_type, $nx, $ny, 100)); $plot->SetPlotType($plot_type); $plot->SetTitle("Serialize/Unserialize Tests\n{$plot_type} - {$data_type}"); $plot->SetXTickIncrement(5); $plot->SetYTickIncrement(10); $plot->SetPlotBorderType('full'); $plot->SetDrawXGrid(True); $plot->SetDrawYGrid(True); $plot->SetXTitle('X Axis Title'); $plot->SetYTitle('Y Axis Title'); # Select data labels or tick labels based on data type: if ($data_type == 'data-data') { $plot->SetXDataLabelPos('none'); $plot->SetXTickLabelPos('plotdown'); $plot->SetXTickPos('plotdown'); } elseif ($data_type == 'text-data') { $plot->SetXDataLabelPos('plotdown'); $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); } elseif ($data_type == 'data-data-yx') { $plot->SetYDataLabelPos('none'); $plot->SetYTickLabelPos('plotleft'); $plot->SetYTickPos('plotleft'); } elseif ($data_type == 'text-data-yx') { $plot->SetYDataLabelPos('plotleft'); $plot->SetYTickLabelPos('none'); $plot->SetYTickPos('none'); } return $plot; }
require 'mem_image.php'; $graph = new PHPlot(500, 300); $graph->SetDataType('data-data'); //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->SetMarginsPixels(null, null, 40, null); $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->SetXTickIncrement(5); //Define the Y axis $graph->SetYTickIncrement(500); $graph->SetPrecisionY(0); $graph->SetLightGridColor('blue'); //Disable image output $graph->SetPrintImage(false); //Draw the graph $graph->DrawGraph(); $pdf = new PDF_MemImage(); $pdf->AddPage(); $pdf->GDImage($graph->img, 30, 20, 140); $pdf->Output();
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->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
} // Read and check the file header. $row = fgetcsv($f); if ($row === FALSE || $row[0] != 'Date' || $row[1] != 'Open' || $row[2] != 'High' || $row[3] != 'Low' || $row[4] != 'Close') { fwrite(STDERR, "Incorrect header in: {$filename}\n"); return FALSE; } // Read the rest of the file and convert. while ($d = fgetcsv($f)) { $data[] = array('', strtotime($d[0]), $d[1], $d[2], $d[3], $d[4]); } fclose($f); return $data; } $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetTitle("Candlesticks Financial Plot (data-data)\nMSFT Q1 2009"); $plot->SetDataType('data-data'); $plot->SetDataValues(read_prices_data_data(DATAFILE)); $plot->SetPlotType('candlesticks'); $plot->SetDataColors(array('SlateBlue', 'black', 'SlateBlue', 'black')); $plot->SetXLabelAngle(90); $plot->SetXLabelType('time', '%Y-%m-%d'); $plot->SetXTickIncrement(7 * 24 * 60 * 60); // 1 week interval if (method_exists($plot, 'TuneYAutoRange')) { $plot->TuneYAutoRange(0); } // Suppress Y zero magnet (PHPlot >= 6.0.0) $plot->DrawGraph();
# To get a repeatable test with 'random' data: mt_srand(1); # Need a base date/time: Can't just use 0 due to UTC/local differences: $base_time = mktime(0, 0, 0, 1, 1, 2000); # Twenty minutes: $interval = 20 * 60; # Random data at intervals: $data = array(); $t = $base_time; for ($i = 1; $i <= 12; $i++) { $data[] = array('', $t, mt_rand(0, 100)); $t += $interval; } $p = new PHPlot(600, 400); $p->SetTitle('Meaningless Data with Time X Tick Labels'); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetXLabelType('time'); $p->SetXTimeFormat('%H:%M'); $p->SetXTitle('Elapsed Time (hours:minutes)'); # Turn off X data labels, use tick labels only: $p->SetXDataLabelPos('none'); $p->SetXTickLabelPos('plotdown'); # Even though tick values are given, it makes up its own unless: $p->SetXTickIncrement($interval); $p->SetDrawXGrid(True); # Set the Y min and max, since the data is 0:100 $p->SetPlotAreaWorld(NULL, 0, NULL, 100); $p->SetYTitle('Meaningless Value'); $p->SetPlotType('lines'); $p->DrawGraph();
include "../phplot.php"; $graph = new PHPlot($xsize_in, $ysize_in); $graph->SetDataType($which_data_type); // Must be first thing $graph->SetDataValues($data); //Optional Settings (Don't need them) // $graph->SetTitle("This is a\n\rmultiple line title\n\rspanning three lines."); $graph->SetTitle($title); $graph->SetXTitle($xlbl, $which_xtitle_pos); $graph->SetYTitle($ylbl, $which_ytitle_pos); $graph->SetLegend(array("A", "Bee", "Cee", "Dee")); $graph->SetFileFormat($which_fileformat); $graph->SetPlotType($which_plot_type); $graph->SetUseTTF($which_use_ttf); $graph->SetYTickIncrement($which_yti); $graph->SetXTickIncrement($which_xti); $graph->SetXTickLength($which_xtl); $graph->SetYTickLength($which_ytl); $graph->SetXTickCrossing($which_xtc); $graph->SetYTickCrossing($which_ytc); $graph->SetXTickPos($which_xtick_pos); $graph->SetYTickPos($which_ytick_pos); $graph->SetShading($which_shading); $graph->SetLineWidth($which_line_width); $graph->SetErrorBarLineWidth($which_errorbar_line_width); $graph->SetDrawDashedGrid($which_dashed_grid); switch ($which_draw_grid) { case 'x': $graph->SetDrawXGrid(TRUE); $graph->SetDrawYGrid(FALSE); break;
} # Make a random data point, and add a row to the data array: $d += mt_rand(-200, 250) / 100; $data[] = array($label, $ts, $d); # Step to next hour: $ts += 3600; } $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); // For presentation in the manual $plot->SetTitle('Hourly Data Example Plot'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetPlotType('lines'); # Make the X tick marks (and therefore X grid lines) 24 hours apart: $plot->SetXTickIncrement(60 * 60 * 24); $plot->SetDrawXGrid(True); # Anchor the X tick marks at midnight. This makes the X grid lines act as # separators between days of the week, regardless of the starting hour. # (Except this messes up around daylight saving time changes.) $plot->SetXTickAnchor($tick_anchor); # We want both X axis data labels and X tick labels displayed. They will # be positioned in a way that prevents them from overwriting. $plot->SetXDataLabelPos('plotdown'); $plot->SetXTickLabelPos('plotdown'); # Increase the left and right margins to leave room for weekday labels. $plot->SetMarginsPixels(50, 50); # Tick labels will be formatted as date/times, showing the date: $plot->SetXLabelType('time', '%Y-%m-%d'); # ... but then we must reset the data label formatting to no formatting. $plot->SetXDataLabelType('');
require_once 'phplot.php'; $data = array(); # This is a cubic equation with roots at -8, 2, 10 for ($x = -10; $x <= 10; $x++) { $data[] = array('', $x, ($x + 8) * ($x - 2) * ($x - 10)); } $p = new PHPlot(400, 800); $p->SetPrintImage(FALSE); $p->SetPlotBorderType('full'); $p->SetTitle("Set/Reset Parameters Test (1)\n" . "Top: Parameters Set\n" . "Bottom: Parameters Reset"); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotType('lines'); $p->SetLegend('Y = F(X)'); $p->SetLegendPixels(100, 200); $p->SetXTickIncrement(5.0); $p->SetYTickIncrement(50.0); $p->SetXTitle('X Axis'); $p->SetYTitle('Y Axis'); $p->SetXAxisPosition(-228); $p->SetYAxisPosition(7); $p->SetPlotAreaPixels(70, 80, 380, 400); $p->DrawGraph(); $p->SetLegendPixels(); $p->SetXTickIncrement(); $p->SetYTickIncrement(); $p->SetXAxisPosition(); $p->SetYAxisPosition(); $p->SetPlotAreaPixels(70, 450, 380, 750); $p->DrawGraph(); $p->PrintImage();
<?php # $Id$ # PHPlot test: Return image encoded as raw require_once 'phplot.php'; $data = array(); for ($i = 0; $i <= 360; $i += 15) { $theta = deg2rad($i); $data[] = array('', $i, cos($theta), sin($theta)); } $p = new PHPlot(800, 600); $p->SetPrintImage(False); $p->SetFailureImage(False); $p->SetTitle('PHPlot Test - Raw Image Encoding'); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetXDataLabelPos('none'); $p->SetXTickIncrement(90); $p->SetYTickIncrement(0.2); $p->SetPlotAreaWorld(0, -1, 360, 1); $p->SetDrawXGrid(True); $p->SetDrawYGrid(True); $p->SetPlotType('lines'); $p->DrawGraph(); $data = $p->EncodeImage('raw'); // fwrite(STDERR, "EncodeImage('raw') size = " . strlen($data) . "\n"); echo $data;
<?php # $Id$ # Test types of label formatting 2 (custom, data:3) require_once 'phplot.php'; function my_format($val, $arg) { $m = (int) ($val / 60); $h = (int) ($m / 60); $m %= 60; return sprintf("%dH%dM", $h, $m); } $data = array(); for ($i = 0; $i < 10; $i++) { $data[] = array('', 4000 * $i, 1234 * $i); } $p = new PHPlot(800, 600); $p->SetTitle("Label Format Test 2"); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetXDataLabelPos('none'); $p->SetXTickIncrement(2000); $p->SetYTickIncrement(1000); $p->SetPlotType('lines'); $p->SetXLabelType('custom', 'my_format'); $p->SetXTitle("X: custom H:M"); $p->SetYLabelType('data', 3); $p->SetYTitle("Y: data, prec=3"); $p->DrawGraph();
function plot_guifi() { include drupal_get_path('module', 'guifi') . '/contrib/phplot/phplot.php'; $result = db_query("select COUNT(*) as num, MONTH(FROM_UNIXTIME(timestamp_created)) as mes, YEAR(FROM_UNIXTIME(timestamp_created)) as ano from {guifi_location} where status_flag='Working' GROUP BY YEAR(FROM_UNIXTIME(timestamp_created)),MONTH(FROM_UNIXTIME(timestamp_created)) "); $inicial = 5; $nreg = $inicial; $tot = 0; $ano = 2004; $mes = 5; $items = 2004; $label = ""; while ($record = db_fetch_object($result)) { if ($record->ano >= 2004) { if ($mes == 12) { $mes = 1; $ano++; } else { $mes++; } while ($ano < $record->ano || $mes < $record->mes) { $nreg++; if ($mes == 6) { $label = $ano; } else { $label = ''; } $data[] = array("{$label}", $nreg, $tot, ''); if ($mes == 12) { $mes = 1; $ano++; } else { $mes++; } } $tot += $record->num; $nreg++; if ($mes == 6) { $label = $ano; } else { $label = ''; } $data[] = array("{$label}", $nreg, $tot, ''); } else { $tot += $record->num; } } while ($mes < 12) { $nreg++; $mes++; if ($mes == 6) { $label = $ano; } else { $label = ''; } $data[] = array("{$label}", $nreg, ""); } $items = ($ano - $items + 1) * 12; if ($tot % 1000 < 30) { $data[$nreg - $inicial - 1][3] = $tot; $vt = floor($tot / 1000) * 1000; $vtitle = $vt . " " . t('Nodes') . "!!!"; $tcolor = 'red'; } else { $vtitle = t('Working nodes'); $tcolor = 'DimGrey'; } $shapes = array('none', 'circle'); $plot = new PHPlot(200, 150); $plot->SetPlotAreaWorld(0, 0, $items, NULL); $plot->SetFileFormat('png'); $plot->SetDataType("data-data"); $plot->SetDataValues($data); $plot->SetPlotType("linepoints"); $plot->SetYTickIncrement(2000); $plot->SetXTickIncrement(12); $plot->SetSkipBottomTick(TRUE); $plot->SetSkipLeftTick(TRUE); $plot->SetXAxisPosition(0); $plot->SetPointShapes($shapes); $plot->SetPointSizes(10); $plot->SetTickLength(3); $plot->SetDrawXGrid(TRUE); $plot->SetTickColor('grey'); $plot->SetTitle($vtitle); $plot->SetDrawXDataLabelLines(FALSE); $plot->SetXLabelAngle(0); $plot->SetXLabelType('custom', 'Plot1_LabelFormat'); $plot->SetGridColor('red'); $plot->SetPlotBorderType('left'); $plot->SetDataColors(array('orange')); $plot->SetTextColor('DimGrey'); $plot->SetTitleColor($tcolor); $plot->SetLightGridColor('grey'); $plot->SetBackgroundColor('white'); $plot->SetTransparentColor('white'); $plot->SetXTickLabelPos('none'); $plot->SetXDataLabelPos('plotdown'); $plot->SetIsInline(TRUE); $plot->DrawGraph(); }
<?php # PHPlot Example - Horizontal Stacked Bars require_once 'phplot.php'; $column_names = array('Beef', 'Fish', 'Pork', 'Chicken', 'Butter', 'Cheese', 'Ice Cream'); // | | | | | | | $data = array(array('1910', 48.5, 11.2, 38.2, 11.0, 18.4, 3.9, 1.9), array('1930', 33.7, 10.2, 41.1, 11.1, 17.6, 4.7, 9.699999999999999), array('1950', 44.6, 11.9, 43.0, 14.3, 10.9, 7.7, 17.4), array('1970', 79.59999999999999, 11.7, 48.1, 27.4, 5.4, 11.4, 17.8), array('1990', 63.9, 14.9, 46.4, 42.4, 4.0, 24.6, 15.8)); $plot = new PHPlot(800, 500); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetTitle("U.S. Annual Per-Capita Consumption\n" . "of Selected Meat and Dairy Products"); $plot->SetLegend($column_names); # Move the legend to the lower right of the plot area: $plot->SetLegendPixels(700, 300); $plot->SetDataValues($data); $plot->SetDataType('text-data-yx'); $plot->SetPlotType('stackedbars'); $plot->SetXTitle('Pounds Consumed Per Capita'); # Show data value labels: $plot->SetXDataLabelPos('plotstack'); # Rotate data value labels to 90 degrees: $plot->SetXDataLabelAngle(90); # Format the data value labels with 1 decimal place: $plot->SetXDataLabelType('data', 1); # Specify a whole number for the X tick interval: $plot->SetXTickIncrement(20); # Disable the Y tick marks: $plot->SetYTickPos('none'); $plot->DrawGraph();
# $Id$ # Testing phplot - "SAR Data" (whatever that is), from a posting on Help # "What I would like to see is ALL the data in the graph (all ticks), but only # X-axis labels for every four hours,ie. 04:00, 08:00, 12:00, 16:00, 20:00 # and 00:00." require_once 'phplot.php'; # Random data for 24 hours at 10 minute intervals, with dummy 0,0 entry: $data[0] = array('00:00', 0, NULL); for ($i = 1; $i < 48 * 6; $i++) { $data[] = array(sprintf("%02d:%02d", $i / 6, $i % 6 * 10), $i, 10.0 + 10.0 * sin($i * M_PI / 50.0)); } # Wipe all labels except every 4 hours: $n = count($data); for ($i = 0; $i < $n; $i++) { if ($i % 24 != 0) { $data[$i][0] = ''; } } $p = new PHPlot(1024, 768); $p->SetTitle('Test: intermittent X labels'); $p->SetDataType('data-data'); $p->SetDataValues($data); # Use data labels along with tick marks. Needs SetPlotAreaWord(0,0) to get them # to line up. $p->SetXTickLabelPos('none'); $p->SetXTickIncrement(6); $p->SetYTickIncrement(5); #$p->SetDrawXGrid(true); $p->SetPlotAreaWorld(0, 0); $p->SetPlotType('points'); $p->DrawGraph();
<?php # $Id$ # Test types of label formatting 1 (data:2, printf:%e) require_once 'phplot.php'; $data = array(); for ($i = 0; $i < 10; $i++) { $data[] = array('', 500 * $i, 1234 * $i); } $p = new PHPlot(800, 600); $p->SetTitle("Label Format Test 1"); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetXDataLabelPos('none'); $p->SetXTickIncrement(1000); $p->SetYTickIncrement(1000); $p->SetPlotType('lines'); $p->SetXTitle("X: data, prec=2"); $p->SetXLabelType('data', 2); $p->SetYTitle("Y: printf %8.2e"); $p->SetYLabelType('printf', '%8.2e'); $p->DrawGraph();
<?php # PHPlot Example: Point chart with error bars require_once 'phplot.php'; $data = array(array('', 1, 23.5, 5, 5), array('', 2, 20.1, 3, 3), array('', 3, 19.1, 2, 2), array('', 4, 16.8, 3, 3), array('', 5, 18.4, 4, 6), array('', 6, 20.5, 3, 2), array('', 7, 23.2, 4, 4), array('', 8, 23.1, 5, 2), array('', 9, 24.5, 2, 2), array('', 10, 28.1, 2, 2)); $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); $plot->SetPlotType('points'); $plot->SetDataType('data-data-error'); $plot->SetDataValues($data); # Main plot title: $plot->SetTitle('Points Plot With Error Bars'); # Set data range and tick increments to get nice even numbers: $plot->SetPlotAreaWorld(0, 0, 11, 40); $plot->SetXTickIncrement(1); $plot->SetYTickIncrement(5); # Draw both grids: $plot->SetDrawXGrid(True); $plot->SetDrawYGrid(True); # Is default # Set some options for error bars: $plot->SetErrorBarShape('tee'); # Is default $plot->SetErrorBarSize(10); $plot->SetErrorBarLineWidth(2); # Use a darker color for the plot: $plot->SetDataColors('brown'); $plot->SetErrorBarColors('brown'); # Make the points bigger so we can see them: $plot->SetPointSizes(10); $plot->DrawGraph();
$range = "{$xmin} : {$xmax}"; } $title = "Date/time X Auto-Range Test: [{$range}]"; if (isset($mintick)) { $title .= "\nX Min Ticks = {$mintick}"; } if (isset($xtickinc)) { $title .= "\nX Tick Increment = {$xtickinc}"; } if (isset($tickanchor)) { $title .= "\nX Tick Anchor = {$tickanchor}"; } $p = new PHPlot(800, 800); $p->SetTitle($title); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetXDataLabelPos('none'); $p->SetPlotType('lines'); # Format labels as date/time: $p->SetXLabelType('time', $dtformat); $p->SetXLabelAngle(90); if (isset($mintick)) { $p->TuneXAutoTicks($mintick); } if (isset($tickanchor)) { $p->SetXTickAnchor($tickanchor); } if (isset($xtickinc)) { $p->SetXTickIncrement($xtickinc); } $p->DrawGraph();
function guifi_stats_chart07() { 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 = "0"; } //"3671"; } else { $zone_id = "0"; } $avalue = array(); $adata = array(); for ($i = 0; $i < 10; $i++) { $adata[] = array(0, 0); } $vsql = "select sum(if(timestamp_created >= " . $datemin . ",1,0)) as num, count(*) as total, zone_id\n from {guifi_location}\n where 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)) { if ($record->total >= 20) { $vn = $record->num / $record->total * 100; $vmin = 0; for ($i = 1; $i < 10; $i++) { if ($adata[$vmin][1] > $adata[$i][1]) { $vmin = $i; } } if ($vn > $adata[$vmin][1]) { $adata[$vmin][0] = $record->zone_id; $adata[$vmin][1] = $vn; } } } for ($i = 0; $i < 10; $i++) { if ($adata[$i][1] != 0) { $avalue[$adata[$i][0]] = $adata[$i][1]; } } arsort($avalue); foreach ($avalue as $key => $value) { if ($value != 0) { $data[] = array(substr(guifi_get_zone_name($key), 0, 20) . " �", $value); } } $shapes = array('none'); $plot = new PHPlot($gwidth, $gheight); $plot->SetPlotAreaWorld(0, 0, NULL, NULL); $plot->SetFileFormat('png'); $plot->SetDataType("text-data"); $plot->SetDataValues($data); $plot->SetPlotType("bars"); $plot->SetXTickIncrement(1); $plot->SetSkipBottomTick(TRUE); $plot->SetSkipLeftTick(TRUE); $plot->SetTickLength(0); //$plot->SetXTickPos('none'); $plot->SetYDataLabelPos('plotin'); $plot->SetYLabelType('data', 0); $plot->SetTickColor('grey'); $plot->SetTTFPath($gDirTTFfonts); $plot->SetFontTTF('title', 'Vera.ttf', 12); $plot->SetFontTTF('x_label', 'Vera.ttf', 8); if (isset($_GET['title'])) { $plot->SetTitle("guifi.net \n" . t($_GET['title'])); } else { if ($zone_id == "0") { $plot->SetTitle("guifi.net \n" . t('Largest annual increase')); } else { $plot->SetTitle("guifi.net " . t('zone') . ": " . guifi_get_zone_name($zone_id) . "\n" . t('Largest annual increase')); } } //$plot->SetXTitle(t('Zones')); $plot->SetYTitle(t('% increase')); $plot->SetXDataLabelPos('plotdown'); //$plot->SetXLabelAngle(45); $plot->SetXDataLabelAngle(75); $plot->SetGridColor('red'); $plot->SetPlotBorderType('left'); $plot->SetDataColors(array('orange')); $plot->SetTextColor('DimGrey'); $plot->SetTitleColor('DimGrey'); $plot->SetLightGridColor('grey'); $plot->SetBackgroundColor('white'); $plot->SetTransparentColor('white'); $plot->SetIsInline(TRUE); $plot->DrawGraph(); }
$tp = array(); } $tp = array_merge(array('c' => 10, 't' => 1, 'ar' => FALSE), $tp); require_once 'phplot.php'; # Extract all test parameters as local variables: extract($tp); $title = "Log/Log Axis Test\nPlotting: XY = {$c}\n" . "Tick step: " . (empty($t) ? "Auto" : $t) . ", " . "Range: " . ($ar ? "Auto" : "Manually set"); # Plot X*Y=C $data = array(); for ($x = 1; $x <= $c; $x++) { $data[] = array('', $x, $c / $x); } $p = new PHPlot(800, 600); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetTitle($title); $p->SetXScaleType('log'); $p->SetYScaleType('log'); if (empty($t)) { $p->SetXTickIncrement($t); $p->SetYTickIncrement($t); } if (!$ar) { $p->SetPlotAreaWorld(0, 1, $c + 1, $c + 1); } $p->SetXTickAnchor(0); $p->SetYTickAnchor(0); $p->SetDrawXGrid(True); $p->SetDrawYGrid(True); $p->SetPlotType('lines'); $p->DrawGraph();
# this script. The parameters are shown in the defaults array below: if (!isset($tp)) { $tp = array(); } $tp = array_merge(array('title' => 'Tick Count:', 'xmin' => 0, 'xmax' => 98, 'ymin' => 0, 'ymax' => 55, 'xti' => 10, 'yti' => 10), $tp); require_once 'phplot.php'; # The data points don't matter at all. The range is set with SetPlotAreaWorld. $data = array(array('', 0, 0), array('', 1, 1)); $p = new PHPlot(); $subtitle = " World: ({$tp['xmin']}, {$tp['ymin']}) :" . " ({$tp['xmax']}, {$tp['ymax']})" . " Tickstep: ({$tp['xti']}, {$tp['yti']})"; $p->SetTitle($tp['title'] . $subtitle); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetXDataLabelPos('none'); $p->SetXTitle('X'); $p->SetYTitle('Y'); $p->SetPlotAreaWorld($tp['xmin'], $tp['ymin'], $tp['xmax'], $tp['ymax']); $p->SetXTickIncrement($tp['xti']); $p->SetYTickIncrement($tp['yti']); #$p->SetSkipTopTick(False); # Draw both grids: $p->SetDrawXGrid(True); $p->SetDrawYGrid(True); # Axes on all sides: $p->SetXTickPos('both'); $p->SetXTickLabelPos('both'); $p->SetYTickPos('both'); $p->SetYTickLabelPos('both'); $p->SetPlotBorderType('full'); $p->SetPlotType('lines'); $p->DrawGraph();
<?php # Typical bars with labels, for manual. require_once 'phplot.php'; $data = array(array('First', 10), array('Second', 20), array('Third', 30)); $p = new PHPlot(400, 300); $p->SetDataType('text-data-yx'); $p->SetDataValues($data); $p->SetPlotType('bars'); $p->SetTitle('Horizontal Bar Plot With Labels'); $p->SetXTitle('Dependent Variable'); $p->SetYTitle('Independent Variable'); $p->SetYDataLabelPos('plotleft'); $p->SetYTickPos('none'); $p->SetXDataLabelPos('plotin'); $p->SetPlotAreaWorld(0, NULL, 40, NULL); $p->SetXTickIncrement(5); $p->SetImageBorderType('plain'); $p->DrawGraph();
<?php # $Id$ # Test types of label formatting 4 (time, data:0:prefix+suffix) require_once 'phplot.php'; $data = array(); $t = mktime(12, 0, 0, 6, 1, 2000); for ($i = 0; $i < 12; $i++) { $data[] = array('', $t, $i * 13.4); $t += 60 * 60 * 24; } $p = new PHPlot(800, 600); $p->SetTitle("Label Format 4"); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetXDataLabelPos('none'); $p->SetXTickIncrement(60 * 60 * 24); $p->SetYTickIncrement(10); $p->SetPlotType('lines'); $p->SetXLabelType('time', '%m/%d'); $p->SetXTitle("X: time MM/DD"); $p->SetYLabelType('data', 0, '$', '#'); $p->SetYTitle("Y: data, prec=0, prefix=\$, suffix=#"); $p->DrawGraph(); #fwrite(STDERR, print_r($p, True));
# Printing helper function prif($name, &$var, $before = '') { return "{$before} {$name}=" . (isset($var) ? $var : "n/a"); } # Auto title: $title = 'X/Y Tick Anchors' . (empty($subtitle) ? "\n" : " - {$subtitle}\n") . prif('X tick anchor', $x_tick_anchor) . prif('Y tick anchor', $y_tick_anchor, ',') . prif('X tick inc.', $x_tick_step, ',') . prif('Y tick inc.', $y_tick_step, ','); $data = array(); for ($x = $start; $x <= $stop; $x += $delta) { $data[] = array('', $x, $x); } $plot = new PHPlot(800, 600); $plot->SetTitle($title); $plot->SetPlotType('lines'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetDrawXGrid(True); $plot->SetDrawYGrid(True); if (isset($x_tick_step)) { $plot->SetXTickIncrement($x_tick_step); } if (isset($y_tick_step)) { $plot->SetYTickIncrement($y_tick_step); } if (isset($x_tick_anchor)) { $plot->SetXTickAnchor($x_tick_anchor); } if (isset($y_tick_anchor)) { $plot->SetYTickAnchor($y_tick_anchor); } $plot->DrawGraph();
# Y2 = cos(x) $end = M_PI * 2.0; $delta = $end / 20.0; $data = array(); for ($x = 0; $x <= $end; $x += $delta) { $data[] = array('', $x, sin($x), cos($x)); } $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); $plot->SetPlotType('lines'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); # Main plot title: $plot->SetTitle('Line Plot, Sin and Cos'); # Make a legend for the 2 functions: $plot->SetLegend(array('sin(t)', 'cos(t)')); # Select a plot area and force ticks to nice values: $plot->SetPlotAreaWorld(0, -1, 6.8, 1); # Even though the data labels are empty, with numeric formatting they # will be output as zeros unless we turn them off: $plot->SetXDataLabelPos('none'); $plot->SetXTickIncrement(M_PI / 8.0); $plot->SetXLabelType('data'); $plot->SetPrecisionX(3); $plot->SetYTickIncrement(0.2); $plot->SetYLabelType('data'); $plot->SetPrecisionY(1); # Draw both grids: $plot->SetDrawXGrid(True); $plot->SetDrawYGrid(True); $plot->DrawGraph();
# Need to set the font for TTF even if legendfont isn't given, to get the size. if ($tp['use_ttf']) { if (isset($tp['legendfont'])) { $p->SetFont('legend', $tp['legendfont'], $tp['ttfsize']); } else { $p->SetFont('legend', $tp['ttfont'], $tp['ttfsize']); } } elseif (isset($tp['legendfont'])) { $p->SetFont('legend', $tp['legendfont']); } $p->SetLegend($tp['text']); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotType('lines'); $p->SetXDataLabelPos('none'); $p->SetXTickIncrement(1.0); $p->SetYTickIncrement(1.0); if (isset($tp['textalign'])) { if (isset($tp['colorboxalign'])) { $p->SetLegendStyle($tp['textalign'], $tp['colorboxalign']); } else { $p->SetLegendStyle($tp['textalign']); } } if (isset($tp['px']) && isset($tp['py'])) { $p->SetLegendPixels($tp['px'], $tp['py']); } if (isset($tp['wx']) && isset($tp['wy'])) { $p->SetLegendWorld($tp['wx'], $tp['wy']); } if (isset($tp['cbwa'])) {
require_once 'phplot.php'; $data = array(array('', -1000, 1000), array('', -500, 23456), array('', 0, 800), array('', 500, 234100), array('', 1000, 1234567), array('', 1500, 100000), array('', 2000, 1901000), array('', 2500, 999999)); $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();
<?php # $Id$ # Testing phplot - data-data ordering require_once 'phplot.php'; # 10 lines, one for each shape: $data = array(array('', 1, 20), array('', 2, 2), array('', 3, 19), array('', 4, 3), array('', 6, 4), array('', 7, 17), array('', 8, 5), array('', 9, 16), array('', 5, 18), array('', 10, 6)); $p = new PHPlot(); $p->SetTitle('Out-of-order data-data points'); $p->SetPlotType('lines'); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotAreaWorld(0, 0, 12, 25); $p->SetXTickIncrement(1); $p->SetYTickIncrement(1); # We don't use the data labels (all set to '') so might as well turn them off: $p->SetXDataLabelPos('none'); # Draw both grids: $p->SetDrawXGrid(True); $p->SetDrawYGrid(True); # The default $p->DrawGraph();
# $Id$ # PHPlot test: Two plots on image with auto-scaling require_once 'phplot.php'; $data1 = array(array('', 0, 10, 50), array('', 1, 20, 40), array('', 2, 30, 20), array('', 3, 40, 0)); $data2 = array(array('', 0, 10, 80), array('', 1, 20, 40), array('', 2, 90, 20), array('', 3, 40, 10), array('', 7, 50, 5), array('', 9, 0, 0)); $p = new PHPlot(800, 600); $p->SetPrintImage(0); // Do not output image until told // First plot: $p->SetDataValues($data1); $p->SetDataType('data-data'); $p->SetPlotType('lines'); $p->SetTitle('Two plots with auto scaling'); $p->SetXTitle('X Axis Title 1'); $p->SetYTitle('Y Axis Title 1'); $p->SetXTickIncrement(0.5); $p->SetPlotAreaPixels(50, 50, 350, 550); $p->DrawGraph(); // Second plot: $p->SetDataValues($data2); $p->SetDataType('data-data'); $p->SetPlotType('lines'); $p->SetXTitle('X Axis Title 2'); $p->SetYTitle('Y Axis Title 2'); $p->SetXTickIncrement(NULL); // Reset to auto tick calculation $p->SetPlotAreaWorld(); // Resets scale to auto $p->SetPlotAreaPixels(450, 50, 750, 550); $p->DrawGraph(); // Now output the completed image