license@systemsmanager.net so we can mail you a copy immediately. */ include DIR_WS_CLASSES . 'phplot.php'; $year = $_GET['year'] ? $_GET['year'] : date('Y'); $month = $_GET['month'] ? $_GET['month'] : date('n'); $days = date('t', mktime(0, 0, 0, $month)) + 1; $stats = array(); for ($i = 1; $i < $days; $i++) { $stats[] = array($i, '0', '0'); } $banner_stats_query = smn_db_query("select dayofmonth(banners_history_date) as banner_day, banners_shown as value, banners_clicked as dvalue from " . TABLE_BANNERS_HISTORY . " where banners_id = '" . $banner_id . "' and month(banners_history_date) = '" . $month . "' and year(banners_history_date) = '" . $year . "'"); while ($banner_stats = smn_db_fetch_array($banner_stats_query)) { $stats[$banner_stats['banner_day'] - 1] = array($banner_stats['banner_day'], $banner_stats['value'] ? $banner_stats['value'] : '0', $banner_stats['dvalue'] ? $banner_stats['dvalue'] : '0'); } $graph = new PHPlot(600, 350, 'images/graphs/banner_daily-' . $banner_id . '.' . $banner_extension); $graph->SetFileFormat($banner_extension); $graph->SetIsInline(1); $graph->SetPrintImage(0); $graph->SetSkipBottomTick(1); $graph->SetDrawYGrid(1); $graph->SetPrecisionY(0); $graph->SetPlotType('lines'); $graph->SetPlotBorderType('left'); $graph->SetTitleFontSize('4'); $graph->SetTitle(sprintf(TEXT_BANNERS_DAILY_STATISTICS, $banner['banners_title'], strftime('%B', mktime(0, 0, 0, $month)), $year)); $graph->SetBackgroundColor('white'); $graph->SetVertTickPosition('plotleft'); $graph->SetDataValues($stats); $graph->SetDataColors(array('blue', 'red'), array('blue', 'red')); $graph->DrawGraph(); $graph->PrintImage();
# Specify the font argument as NULL or '' to use the generic one. $plot->DrawText('', 0, $worst_x, $worst_y - 10, $red, 'Bad News!', 'center', 'bottom'); } # Begin main processing: # Fill the data array: $data = get_data(); # Find the best and worst months: get_best_worst($data, $best_index, $best_sales, $worst_index, $worst_sales); # Create the PHPlot object, set title, plot type, data array type, and data: $plot = new PHPlot(800, 600); $plot->SetTitle('Monthly Widget Sales'); $plot->SetPlotType('bars'); $plot->SetDataType('text-data'); $plot->SetDataValues($data); # Borders are needed for the manual: $plot->SetImageBorderType('plain'); # Select X data labels (not tick labels): $plot->SetXTickPos('none'); $plot->SetXTickLabelPos('none'); $plot->SetXDataLabelPos('plotdown'); # Format Y labels as "$nM" with no decimals, steps of 5: $plot->SetYLabelType('data', 0, '$', 'M'); $plot->SetYTickIncrement(5.0); # Force the bottom of the plot to be at Y=0, and omit # the bottom "$0M" tick label because it looks odd: $plot->SetPlotAreaWorld(NULL, 0); $plot->SetSkipBottomTick(True); # Establish the drawing callback to do the annotation: $plot->SetCallback('draw_all', 'annotate_plot', $plot); # Draw the graph: $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(); }
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(); }
} $p->SetYTickLabelPos($tp['yticklabel']); $p->SetYTickPos($tp['yticklabel']); $p->SetXTitle('X TITLE'); $p->SetYTitle('Y TITLE'); # Tick skip tests: if (isset($tp['skiptick'])) { $s = $tp['skiptick']; $n = strlen($s); for ($i = 0; $i < $n; $i++) { switch ($s[$i]) { case 'T': $p->SetSkipTopTick(True); break; case 'B': $p->SetSkipBottomTick(True); break; case 'L': $p->SetSkipLeftTick(True); break; case 'R': $p->SetSkipRightTick(True); break; default: die("Parameter error in tp['skiptick']"); } } } # Tick size: if (isset($tp['xtickcross'])) { $p->SetXTickCrossing($tp['xtickcross']);