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();
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(); }
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(); }
# $Id$ # PHPlot test: Coloring various items require_once 'phplot.php'; $data = array(); $x = 0.0; $dx = M_PI / 4.0; for ($i = 0; $i < 50; $i++) { $y = $x * sin($x); $data[] = array('', $i, $y); $x += $dx; } $plot = new PHPlot(800, 600); $plot->SetPlotType('lines'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetLineWidths(2); $plot->SetPlotAreaWorld(0, -40, 50, 40); # Turn everything on to test colors: $plot->SetTitle("Color Tests\n" . " SetGridColor blue (used for axes, legend border)\n" . " SetLightGridColor magenta\n" . " SetTextColor red\n" . " SetTickColor green\n" . " SetTitleColor gold"); $plot->SetDrawXGrid(True); $plot->SetDrawYGrid(True); $plot->SetLegend('Color Tests'); $plot->SetXTitle('X Title Here'); $plot->SetYTitle('Y Title Here'); # Set colors: $plot->SetGridColor('blue'); $plot->SetLightGridColor('magenta'); $plot->SetTextColor('red'); $plot->SetTickColor('green'); $plot->SetTitleColor('gold'); $plot->DrawGraph();
return $labels[(int) $value]; } return $value; } # <=12 13-17 17-28 30-39 40-54 >=55 $data = array(array('Cherry', 1, 1, 2, 2, 4, 3, 3, 4, 3, 5, 5, 6, 6), array('Apple', 2, 1, 9, 2, 7, 3, 4, 4, 7, 5, 3, 6, 7), array('Pear', 3, '', 2, 2, 2, 3, 3, 4, 4, 5, 3, 6, 2), array('Grape', 4, 1, 8, 2, 5, 3, 5, 4, 6, 5, 3, 6, 4), array('Kiwi', 5, '', 0, 2, 3, 3, 4, 4, 4, 5, 5, 6, 2), array('Banana', 6, 1, 5, 2, 4, 3, 6, 4, 3, 5, 3, 6, 4)); $plot = new PHPlot(600, 600); $plot->SetTitle("Flavor Preference By Age Group"); $plot->SetDataType('data-data-xyz'); $plot->SetDataValues($data); $plot->SetPlotType('bubbles'); $plot->SetDataColors('yellow'); // Use same color for all data sets $plot->SetDrawPlotAreaBackground(True); $plot->SetPlotBgColor('plum'); $plot->SetLightGridColor('red'); // Change grid color to make it visible $plot->SetImageBorderType('plain'); $plot->SetPlotBorderType('full'); $plot->SetXTickIncrement(1); // For grid line spacing $plot->SetYTickIncrement(1); $plot->SetPlotAreaWorld(0, 0, 6.5, 6.5); # Establish the handler for the Y label text: $plot->SetYLabelType('custom', 'get_label', $y_labels); $plot->SetXTickPos('both'); // Tick marks on both sides $plot->SetYTickPos('both'); // Tick marks on top and bottom too $plot->SetXDataLabelPos('both'); // X axis data labels top and bottom
# Data for plot #1: stackedbars: $y_title1 = 'Number of positive tests'; $data1 = array(array('1/09', 200, 200, 300), array('2/09', 300, 100, 700), array('3/09', 400, 200, 800), array('4/09', 500, 300, 1200), array('5/09', 400, 400, 2500), array('6/09', 500, 600, 3600), array('7/09', 400, 1200, 3300), array('8/09', 300, 1500, 2500), array('9/09', 200, 1900, 800), array('10/09', 100, 2000, 200), array('11/09', 100, 2500, 100), array('12/09', 100, 2700, 200)); $legend1 = array('Strain A', 'Strain B', 'Strain C'); # Data for plot #2: linepoints: $y_title2 = 'Percent Positive'; $data2 = array(array('1/09', 5), array('2/09', 10), array('3/09', 15), array('4/09', 30), array('5/09', 40), array('6/09', 45), array('7/09', 47), array('8/09', 35), array('9/09', 25), array('10/09', 20), array('11/09', 25), array('12/09', 30)); $legend2 = array('% positive'); $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); // For presentation in the manual $plot->SetPrintImage(False); // Defer output until the end $plot->SetTitle($title); $plot->SetPlotBgColor('gray'); $plot->SetLightGridColor('black'); // So grid stands out from background # Plot 1 $plot->SetDrawPlotAreaBackground(True); $plot->SetPlotType('stackedbars'); $plot->SetDataType('text-data'); $plot->SetDataValues($data1); $plot->SetYTitle($y_title1); # Set and position legend #1: $plot->SetLegend($legend1); $plot->SetLegendPixels(5, 30); # Set margins to leave room for plot 2 Y title on the right. $plot->SetMarginsPixels(120, 120); # Specify Y range of these data sets: $plot->SetPlotAreaWorld(NULL, 0, NULL, 5000); $plot->SetYTickIncrement(500);