public function testDrawFilledLineGraph() { // Dataset definition $DataSet = new pData(); CSVImporter::importFromCSV($DataSet, dirname(__FILE__) . "/../sample/datawithtitle.csv", ",", array(1, 2, 3), TRUE, 0); $DataSet->AddAllSeries(); $DataSet->SetAbscissaLabelSeries(); // Initialise the graph $canvas = new TestCanvas(); $Test = new pChart(700, 230, $canvas); $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(60, 30, 680, 200); $backgroundStyle = new BackgroundStyle(new Color(255), TRUE); $Test->drawGraphBackground($backgroundStyle); $Test->drawScale($DataSet, ScaleStyle::DefaultStyle(), 0, 2); $Test->drawGrid(new GridStyle(4, TRUE, new Color(230), 50)); // Draw the 0 line $Test->setFontProperties("Fonts/tahoma.ttf", 6); $Test->drawTreshold(0, new Color(143, 55, 72), TRUE, TRUE); // Draw the filled line graph $Test->drawFilledLineGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 50, TRUE); // Finish the graph $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->drawLegend(65, 35, $DataSet->GetDataDescription(), new Color(255)); $Test->setFontProperties("Fonts/tahoma.ttf", 10); $Test->drawTitle(60, 22, "Example 6", new Color(50), 585); $this->assertEquals('9816ffbe4277df46fdce89cdc0b28a47', md5($canvas->getActionLog())); }
public function componentLineGraph() { $DataSet = new pData(); $maxvals = array(); foreach ($this->datasets as $ds_id => $dataset) { $DataSet->AddPoint($dataset['values'], "Serie" . $ds_id, array_keys($dataset['values'])); $maxvals[] = max($dataset['values']); if (isset($dataset['burndown'])) { $amount = count($dataset['values']) > 1 ? $dataset['burndown']['maxEstimation'] / (count($dataset['values']) - 1) : 0; for ($i = 0; $i < count($dataset['values']); $i++) { $burndownValues[] = $dataset['burndown']['maxEstimation'] - $i * $amount; } $DataSet->AddPoint($burndownValues, "Burndown" . $ds_id, $dataset['burndown']['maxEstimation']); } } $DataSet->AddAllSeries(); if (isset($this->labels)) { $DataSet->AddPoint($this->labels, "Labels"); $DataSet->SetAbsciseLabelSerie("Labels"); } else { $DataSet->SetAbsciseLabelSerie(); } foreach ($this->datasets as $ds_id => $dataset) { $DataSet->SetSerieName($dataset['label'], "Serie" . $ds_id); if (isset($dataset['burndown'])) { $DataSet->SetSerieName($dataset['burndown']['label'], "Burndown" . $ds_id); } } if (isset($this->values_title)) { $DataSet->SetYAxisName($this->values_title); } if (isset($this->labels_title)) { $DataSet->SetXAxisName($this->labels_title); } // Initialise the graph $Test = new pChart($this->width, $this->height); $Test->setFixedScale(0, ceil(max($maxvals) / 5) * 5); $Test->setFontProperties(THEBUGGENIE_MODULES_PATH . 'pchart' . DS . 'fonts' . DS . 'DroidSans.ttf', 8); if (isset($this->labels_title)) { $Test->setGraphArea(50, 30, $this->width - 30, $this->height - 45); } else { $Test->setGraphArea(50, 30, $this->width - 30, $this->height - 30); } $Test->drawFilledRoundedRectangle(2, 2, $this->width - 3, $this->height - 3, 5, 240, 240, 240); $Test->drawRoundedRectangle(0, 0, $this->width - 1, $this->height - 1, 5, 230, 230, 230); $Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2); $Test->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the 0 line $Test->setFontProperties(THEBUGGENIE_MODULES_PATH . 'pchart' . DS . 'fonts' . DS . 'DroidSans.ttf', 6); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the cubic curve graph if (isset($this->style) && $this->style == 'curved') { $Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription()); } elseif (isset($this->style) && $this->style == 'filled_line') { $Test->drawFilledLineGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 50, true); } elseif (isset($this->style) && $this->style == 'stacked_bar') { $Test->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 50, true); } elseif (isset($this->style) && $this->style == 'single_bar') { $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE); } else { $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); } if (isset($this->include_plotter) && $this->include_plotter) { $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255); } // Finish the graph $Test->setFontProperties(THEBUGGENIE_MODULES_PATH . 'pchart' . DS . 'fonts' . DS . 'DroidSans.ttf', 8); //$Test->drawLegend(600, 30, $DataSet->GetDataDescription(), 255, 255, 255); $Test->drawLegend(55, 35, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties(THEBUGGENIE_MODULES_PATH . 'pchart' . DS . 'fonts' . DS . 'DroidSansBold.ttf', 10); $Test->drawTitle(50, 22, $this->title, 50, 50, 50, $this->width - 30); $Test->Stroke(); //("example2.png"); }
/* Example6 : A simple filled line graph */ // Standard inclusions include "src/pData.php"; include "src/pChart.php"; // Dataset definition $DataSet = new pData(); $DataSet->ImportFromCSV("Sample/datawithtitle.csv", ",", array(1, 2, 3), TRUE, 0); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie(); // Initialise the graph $Test = new pChart(700, 230); $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(60, 30, 680, 200); $Test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230); $Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2); $Test->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the 0 line $Test->setFontProperties("Fonts/tahoma.ttf", 6); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the filled line graph $Test->drawFilledLineGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 50, TRUE); // Finish the graph $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->drawLegend(65, 35, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties("Fonts/tahoma.ttf", 10); $Test->drawTitle(60, 22, "Example 6", 50, 50, 50, 585); $Test->Render("example6.png");
// $graph->drawGrid(4, true, 230, 230, 230, 100); if ($plugin->getID() == GLOBAL_PLUGIN_ID) { $statement = get_slave_db_handle()->prepare('SELECT Sum(GlobalHits) FROM Plugin'); $statement->execute(); $serverStarts = $statement->fetch()[0]; $serversLast24Hours = $plugin->countServersLastUpdated(time() - SECONDS_IN_DAY); } else { $serverStarts = $plugin->getGlobalHits(); $serversLast24Hours = $plugin->countServersLastUpdated(time() - SECONDS_IN_DAY); } // Draw the footer $graph->setFontProperties('pf_arma_five.ttf', 6); $footer = sprintf('%s servers in the last 24 hours with %s all-time server startups ', number_format($serversLast24Hours), number_format($serverStarts)); $graph->drawTextBox(60, REAL_IMAGE_HEIGHT - 25, REAL_IMAGE_WIDTH - 20, REAL_IMAGE_HEIGHT - 7, $footer, 0, 255, 255, 255, ALIGN_RIGHT, true, 0, 0, 0, 30); // Draw the data $graph->drawFilledLineGraph($dataSet->GetData(), $dataSet->GetDataDescription(), 75, true); // Draw legend $graph->drawLegend(65, 35, $dataSet->GetDataDescription(), 255, 255, 255); // Get the center of the image $authors = $plugin->getAuthors(); if (!empty($authors)) { $title = $pluginName . ' - ' . $authors; } else { $title = $pluginName; } $tahoma = 'tahoma.ttf'; $bounding_box = imagettfbbox(11, 0, $tahoma, $title); $center_x = ceil((REAL_IMAGE_WIDTH - $bounding_box[2]) / 2); // Draw the title there $graph->setFontProperties($tahoma, 11); // Switch to font size 10
//---------------------------- Draw points if ($_GET['points'] == '1') { $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), $point); //plot } //---------------------------- Draw graphics if ($_GET['gtype'] == 'curve') { $Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription()); } elseif ($_GET['gtype'] == 'bar') { $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), FALSE); } elseif ($_GET['gtype'] == 'line') { $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); } elseif ($_GET['gtype'] == 'plot') { $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), $point); } elseif ($_GET['gtype'] == 'fline') { $Test->drawFilledLineGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 20, FALSE); } elseif ($_GET['gtype'] == 'fcurve') { $Test->drawFilledCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription(), 0.1, 20, FALSE); } else { } //---------------------------- Labels if ($labels) { if ($p != '' && $n1 != "") { $h = count($hours); for ($i = $h / 2; $i > 0; $i--) { if ($hours[$i] != 0) { $r = $hours[$i]; } } } if ($middleall = 0) {
$pChartDataSet->SetAbsciseLabelSerie("Serie1"); $pChartDataSet->SetYAxisName("在\n线\n人\n数\n//\n人"); $pChartDataSet->SetYAxisFormat("floor"); $pChartDataSet->SetXAxisFormat("number"); // 设置作图区域 $pChartGraph = new pChart($imgWidth, 253); $pChartGraph->drawGraphAreaGradient(90, 90, 90, 90, TARGET_BACKGROUND); $pChartGraph->setGraphArea(70, 30, $imgWidth + 70 - 90, 253 + 30 - 80); $pChartGraph->setFontProperties(DRAWFONE_PATH, 8); $pChartGraph->drawScale($pChartDataSet->GetData(), $pChartDataSet->GetDataDescription(), SCALE_NORMAL, 250, 250, 250, TRUE, 0, 0, FALSE, 1); // 开始作图 $pChartGraph->setColorPalette(0, 0, 255, 255); $pChartGraph->drawGraphAreaGradient(40, 40, 40, -50); $pChartGraph->drawGrid(1, TRUE, 115, 115, 115, 10); $pChartGraph->setShadowProperties(3, 3, 0, 0, 0, 30, 4); $pChartGraph->drawFilledLineGraph($pChartDataSet->GetData(), $pChartDataSet->GetDataDescription(), 25); $pChartGraph->clearShadow(); $pChartGraph->setFontProperties(DRAWFONE_PATH, 10); $pChartGraph->drawTitle($imgWidth / 2, 22, "实时在线人数查询(" . $dateTime . ") 峰值( " . $maxNumberIndex . ", " . $maxNumber . "人 )", 255, 255, 255, 585); $pChartGraph->writeValues($pChartDataSet->GetData(), $pChartDataSet->GetDataDescription(), "Serie2"); // 结束 $pChartGraph->Stroke(); // $pChartGraph->Render("RealTimeOnLine.png"); // echo "<img src = 'RealTimeOnLine.png'>"; // $fileNameTxt = "Cache/XYInfo.".$plat.$server.$dateTime.".txt"; // $file = fopen($fileNameTxt,"w"); // $info = $pChartGraph->DivisionWidth.",".$pChartGraph->GArea_Y2.",".$pChartGraph->VMin.",".$pChartGraph->DivisionRatio; // fwrite($file,$info); // fclose($file); ?>
/** * Draw line style chart * @return unknown */ protected function drawLine() { // prepare font & series $this->_prepareSerie(); $this->_prepareFont(); // init chart params $outer_w = $this->w - 5; // Outer frame witdh $outer_h = $this->h - 5; // Outer frame heigth $inner_w = $this->w - 7; // Inner frame witdh $inner_h = $this->h - 7; // Inner frame heigth $chart_w = $this->w - 150; // Chart frame witdh $chart_h = $this->h - 40; // Chart frame heigth $title_w = $this->w - 200; // Title width $title_h = 45; // Title height $legend_w = $chart_w + 30; // Legend width $legend_h = 40; // Legend height // chart styles $grid = isset($this->p['grid']) ? $this->p['grid'] : false; $plot = isset($this->p['plot']) ? $this->p['plot'] : false; $curve = isset($this->p['curve']) ? $this->p['curve'] : false; $filled = isset($this->p['filled']) ? $this->p['filled'] : false; // fill chart $this->chart->drawBackground(255, 255, 255); $this->chart->setFontProperties($this->font, 7); // set font and size $this->chart->drawRoundedRectangle(5, 5, $outer_w, $outer_h, 10, 230, 230, 230); // drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B) $this->chart->drawFilledRoundedRectangle(7, 7, $inner_w, $inner_h, 10, 240, 240, 240); // drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B) $this->chart->setGraphArea(70, 40, $chart_w, $chart_h); // setGraphArea($X1,$Y1,$X2,$Y2) $this->chart->drawGraphArea(255, 255, 255, TRUE); // drawGraphArea($R,$G,$B) $this->chart->drawScale($this->data->GetData(), $this->data->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, $this->margin, $this->skip); // drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1,$RightScale=FALSE) $this->data->RemoveSerie('DEFAULT_SCALE'); // clear scale serie for setScale method // draw grid if ($grid) { $this->chart->drawGrid(3, TRUE, 230, 230, 230, 50); // drawGrid($LineWidth,$Mosaic=TRUE,$R=220,$G=220,$B=220,$Alpha=255) } // draw the 0 line //$this->chart->setFontProperties($this->font,6); //$this->chart->drawTreshold(0,143,55,72,TRUE,TRUE); // draw the cubic curve graph if ($curve) { $this->chart->drawCubicCurve($this->data->GetData(), $this->data->GetDataDescription()); if ($filled) { $this->chart->drawFilledCubicCurve($this->data->GetData(), $this->data->GetDataDescription(), 0.1, 50); // filled cubic curve graph } // draw the line graph } else { $this->chart->drawLineGraph($this->data->GetData(), $this->data->GetDataDescription()); if ($filled) { $this->chart->drawFilledLineGraph($this->data->GetData(), $this->data->GetDataDescription(), 50); } } // plot style point if ($plot) { $this->chart->drawPlotGraph($this->data->GetData(), $this->data->GetDataDescription(), 3, 2, 255, 255, 255, true); // drawPlotGraph(&$Data,&$DataDescription,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1,$Shadow=FALSE) } // add Title $this->chart->setFontProperties($this->font, 10); $this->chart->drawTitle(40, 0, $this->title, 50, 50, 50, $title_w, $title_h); // drawTitle($XPos,$YPos,$Value,$R,$G,$B,$XPos2=-1,$YPos2=-1,$Shadow=FALSE) // add Legend $this->chart->setFontProperties($this->font, 8); $this->chart->drawLegend($legend_w, $legend_h, $this->data->GetDataDescription(), 255, 255, 255); // drawLegend($description,$R,$G,$B) }
require_once '../lib/BackgroundStyle.php'; // Definitions $DataSet = new pData(); $Canvas = new GDCanvas(700, 230); $Chart = new pChart(700, 230, $Canvas); // Dataset CSVImporter::importFromCSV($DataSet, dirname(__FILE__) . "/../sample/datawithtitle.csv", ",", array(1, 2, 3), TRUE, 0); $DataSet->AddAllSeries(); $DataSet->SetAbscissaLabelSeries(); // Initialise the graph $Chart->setFontProperties("../Fonts/tahoma.ttf", 8); $Chart->setGraphArea(60, 30, 680, 200); $Canvas->drawFilledRoundedRectangle(new Point(7, 7), new Point(693, 223), 5, new Color(240), 1, 0, ShadowProperties::NoShadow()); $Canvas->drawFilledRoundedRectangle(new Point(5, 5), new Point(695, 225), 5, new Color(230), 1, 0, ShadowProperties::NoShadow()); $backgroundStyle = new BackgroundStyle(new Color(255), TRUE); $Chart->drawGraphBackground($backgroundStyle); $Chart->drawScale($DataSet, ScaleStyle::DefaultStyle(), 0, 2); $Chart->drawGrid(new GridStyle(4, TRUE, new Color(230), 50)); // Draw the 0 line $Chart->setFontProperties("../Fonts/tahoma.ttf", 6); $Chart->drawTreshold(0, new Color(143, 55, 72), TRUE, TRUE); // Draw the filled line graph $Chart->drawFilledLineGraph($DataSet->getData(), $DataSet->getDataDescription(), 50, True); // Finish the graph $Chart->setFontProperties("../Fonts/tahoma.ttf", 8); $Chart->drawLegend(65, 35, $DataSet->GetDataDescription(), new Color(255)); $Chart->setFontProperties("../Fonts/tahoma.ttf", 10); $Chart->drawTitle(60, 22, "Example 6", new Color(50), 585); $Chart->Render("Example6.png"); header("Content-Type:image/png"); echo file_get_contents("Example6.png");