/** * Create PHPlot instance initializing common options * * @param int $width * @param int $height * @return PHPlot */ private function create($width, $height) { $plot = new PHPlot($width, $height); $plot->SetTTFPath($this->fonts_path); $plot->SetUseTTF(true); return $plot; }
<?php session_start(); require_once 'phplot.php'; echo $_GET[countKeywords]; $data = array(array('新增文件', intval($_GET[countnew])), array('删除文件', intval($_GET[countdel])), array('修改文件', intval($_GET[countmodify]))); $plot = new PHPlot(350, 280); $plot->SetTTFPath('./public'); $plot->SetDefaultTTFont('SIMHEI.TTF'); $plot->SetUseTTF(True); $plot->SetImageBorderType('plain'); $plot->SetPlotType('bars'); $plot->SetDataType('text-data'); $plot->SetPlotBorderType('full'); $plot->SetBackgroundColor('#ffffcc'); $plot->SetDrawPlotAreaBackground(True); $plot->SetPlotBgColor('#ffffff'); $plot->SetDataValues($data); $plot->SetTitle("新增文件数:{$_GET['countnew']} 删除文件数:{$_GET['countdel']} 修改文件数:{$_GET['countmodify']}"); $plot->SetTitleColor('#D9773A'); foreach ($data as $row) { $plot->Setshading(10); } $plot->SetDataBorderColors('black'); $plot->DrawGraph();
# This uses config.php to identify TrueType font locations and names. require_once 'config.php'; # 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' => 'Legend Test', 'suffix' => ' (baseline)', 'use_ttf' => False, 'textalign' => NULL, 'colorboxalign' => NULL, 'legendfont' => NULL, 'line_spacing' => NULL, 'text' => NULL, 'px' => NULL, 'py' => NULL, 'wx' => NULL, 'wy' => NULL, 'ttfont' => $phplot_test_ttfonts['sans'], 'ttfdir' => $phplot_test_ttfdir, 'ttfsize' => 14, 'cbwa' => NULL), $tp); require_once 'phplot.php'; $data = array(array('', 0, 0, 0, 0), array('', 1, 1, 2, 3), array('', 2, 2, 4, 6), array('', 3, 3, 6, 9)); if (!isset($tp['text'])) { $tp['text'] = array('Plot Line 1', 'Longer label for Plot Line 2', 'line 3'); } $p = new PHPlot(800, 600); if ($tp['use_ttf']) { $p->SetTTFPath($tp['ttfdir']); $p->SetDefaultTTFont($tp['ttfont']); } # Set line spacing: if (isset($tp['line_spacing'])) { $p->SetLineSpacing($tp['line_spacing']); } $p->SetTitle($tp['title'] . $tp['suffix']); # 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'])) {
require_once 'phplot.php'; $data = array(); for ($len = 5; $len <= $tp['MaxLen']; $len += 5) { $data[] = array(str_repeat('Label', $len / 5), $len); } $p = new PHPlot(800, 600); $p->SetTitle($tp['title'] . $tp['suffix']); $p->SetDataType('text-data'); $p->SetDataValues($data); # Fix Y ticks $p->SetPlotAreaWorld(NULL, 0, NULL, NULL); $p->SetYTickIncrement(5); # Font: if ($tp['TTF']) { # Using TrueType fonts: Set path and default font. $p->SetTTFPath($phplot_test_ttfdir); $font = $phplot_test_ttfonts[$tp['FontName']]; $p->SetDefaultTTFont($font); # Now select label font with size (if supplied): if (empty($tp['FontSize'])) { $p->SetFont('x_label', $font); } else { $p->SetFont('x_label', $font, $tp['FontSize']); } } else { # Using GD fonts: if (isset($tp['FontSize'])) { $p->SetFont('x_label', $tp['FontSize']); } } # Label angle:
<?php # $Id$ # Testing phplot - Default TT font (2b): Local path and named font. # This test requires a specific font (see TEST_FONT) be present in the images/ # directory. The listed font is redistributable under the Open Fonts License. require_once 'phplot.php'; define('TEST_FONT', 'FreeUniversal-Regular.ttf'); $data = array(array('A', 3, 6), array('B', 2, 4), array('C', 1, 2)); $p = new PHPlot(800, 800); $p->SetDataType('text-data'); $p->SetDataValues($data); $p->SetPlotType('bars'); $p->SetTitle('Local TTF path and SetFontTTF with file basename only'); $p->SetXTitle('X Axis Title'); $p->SetYTitle('Y Axis Title'); $p->SetTTFPath(getcwd() . DIRECTORY_SEPARATOR . 'images'); $p->SetFontTTF('title', TEST_FONT, 18); $p->SetFontTTF('x_title', TEST_FONT, 14); $p->SetFontTTF('y_title', TEST_FONT, 10); $p->DrawGraph(); fwrite(STDERR, "OK defaultfont2b: title font=" . $p->fonts['title']['font'] . "\n");
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(); }
switch ($case) { case 1: # Test: Turn on TTF without path setup $p->SetUseTTF(True); break; case 2: # Test: Bad default font with path $p->SetDefaultTTFont("/no/such/path/to/font.ttf"); break; case 3: # Test: Bad default font without path $p->SetDefaultTTFont("nosuchfont.ttf"); break; case 4: # Test: Bad font path $p->SetTTFPath("/no/such/font/dir"); break; case 5: # Test: Good font path and default, bad font selected $p->SetTTFPath($phplot_test_ttfdir); $p->SetDefaultTTFont($phplot_test_ttfonts['sans']); $p->SetFont('title', 'nosuchfont.ttf', 14); break; default: # Test: Valid font path and font $p->SetTTFPath($phplot_test_ttfdir); $p->SetDefaultTTFont($phplot_test_ttfonts['sans']); $p->SetFont('title', $phplot_test_ttfonts['serif'], 14); } $p->SetPlotType('lines'); $p->DrawGraph();