function drawChart($title, $DataSet, $names, $colors, $legend = false) { // Initialise the graph $Chart = new pChart(1300, 750); $Chart->setFontProperties("Fonts/tahoma.ttf", 8); $Chart->setGraphArea(50, 25, 1200, 725); $Chart->drawGraphArea(255, 255, 255, TRUE); $Chart->drawXYScale($DataSet->GetData(), $DataSet->GetDataDescription(), "ally", "allx", 150, 150, 150, TRUE, 45); $Chart->setLineStyle(4); // Draw the 0 line $Chart->setFontProperties("Fonts/tahoma.ttf", 6); $Chart->drawTreshold(0, 143, 55, 72, TRUE, TRUE); foreach ($colors as $idx => $color) { $Chart->setColorPalette($idx, $color[0], $color[1], $color[2]); } $i = 0; foreach ($names as $name) { $Chart->drawXYGraph($DataSet->GetData(), $DataSet->GetDataDescription(), $name . "y", $name . "x", $i); $i++; } if ($legend) { $Chart->drawLegend(465, 40, $DataSet->GetDataDescription(), 255, 255, 255); } // Finish the graph $Chart->setFontProperties("Fonts/tahoma.ttf", 10); // $Chart->drawTitle(60,22,$title,50,50,50,530); $Chart->Stroke(); }
/** * Генерация графика * @param DataSet $DataSet * @param String $GraphTitle * @param String $safeToFile */ function createGraphToFile($DataSet, $GraphTitle, $safeToFile, $scaleFormat) { // Rotrate $rotate = 30; // Initialise the graph $GraphImage = new pChart(594, 344); $GraphImage->setDateFormat($scaleFormat); // $GraphImage->loadColorPalette(DIR_FONT.'/tones-3.txt'); $GraphImage->setFontProperties(DIR_FONT . "/segoepr.ttf", 8); $GraphImage->setGraphArea(80, 50, 580, 300); $GraphImage->drawFilledRectangle(3, 3, 590, 340, 240, 240, 240); $GraphImage->drawRectangle(0, 0, 593, 343, 230, 230, 230); $GraphImage->drawGraphArea(255, 255, 255, TRUE); $GraphImage->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, $rotate, 0, FALSE); $GraphImage->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the 0 line $GraphImage->setFontProperties(DIR_FONT . "/segoepr.ttf", 6); $GraphImage->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Просто пунктирная линия // Draw the cubic curve graph $GraphImage->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription()); // Draw the line graph //$GraphImage->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); $GraphImage->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255); // Finish the graph $GraphImage->setFontProperties(DIR_FONT . "/segoepr.ttf", 12); $GraphImage->drawTitle(60, 32, $GraphTitle, 50, 50, 50, 600); //$GraphImage->Render(DIR_CACHE . './' . $safeToFile . '.png'); $GraphImage->Stroke(); }
function drawChart($title, $DataSet, $type, $colors, $legend = false) { // Initialise the graph $Chart = new pChart(1300, 700); $Chart->setFontProperties("Fonts/tahoma.ttf", 8); $Chart->setGraphArea(50, 50, 1200, 600); $Chart->drawGraphArea(255, 255, 255, TRUE); $Chart->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 0, TRUE); // Draw the 0 line $Chart->setFontProperties("Fonts/tahoma.ttf", 6); $Chart->drawTreshold(0, 143, 55, 72, TRUE, TRUE); foreach ($colors as $idx => $color) { $Chart->setColorPalette($idx, $color[0], $color[1], $color[2]); } if ($type == "bar") { $Chart->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription()); } else { if ($type == "line") { $Chart->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); } } if ($legend) { $Chart->drawLegend(465, 40, $DataSet->GetDataDescription(), 255, 255, 255); } // Finish the graph $Chart->setFontProperties("Fonts/tahoma.ttf", 10); $Chart->drawTitle(60, 22, $title, 50, 50, 50, 530); $Chart->Stroke(); }
function makeGraph($values, $labels) { $values[] = '0'; $labels[] = ''; // Standard inclusions include_once "charts/pChart.class"; include_once "charts/pData.class"; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint($values, "Serie2"); $DataSet->AddPoint($labels, "Xlabel"); $DataSet->AddSerie("Serie2"); $DataSet->SetAbsciseLabelSerie('Xlabel'); $DataSet->SetSerieName("No Of Births", "Serie2"); // Initialise the graph $Test = new pChart(700, 230); $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(50, 30, 585, 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, TRUE); $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 bar graph $Test->drawOverlayBarGraph($DataSet->GetData(), $DataSet->GetDataDescription()); // Finish the graph $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->drawLegend(600, 30, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties("Fonts/tahoma.ttf", 10); $Test->drawTitle(50, 22, "Change in name popularity", 50, 50, 50, 585); ob_start(); $Test->Stroke(); $img = ob_get_clean(); $img = base64_encode($img); return $img; }
/** * Display chart directly * @return unknown */ public function show() { if (empty($this->cdata)) { require_once 'Hush/Chart/Exception.php'; throw new Hush_Chart_Exception('Empty data exception, please add data first'); } $this->showValue('score'); $method = 'draw' . ucfirst($this->type); if (method_exists($this, $method)) { $this->{$method}(); // insert show serie logic if (count($this->shows) > 0) { foreach ($this->shows as $serie) { $this->chart->writeValues($this->data->GetData(), $this->data->GetDataDescription(), $serie); } } $this->chart->Stroke(); } }
<?php include "./includes/pdata.php"; include "./includes/pchart.php"; if (!isset($_GET['cc']) || !isset($_GET['cn'])) { exit; } $cc = explode(",", $_GET['cc']); $cn = explode(",", $_GET['cn']); $data = new pData(); $data->AddPoint($cn, "Serie1"); $data->AddPoint($cc, "Serie2"); $data->AddAllSeries(); $data->SetAbsciseLabelSerie("Serie2"); $chart = new pChart(350, 180); $chart->createColorGradientPalette(235, 72, 225, 6, 199, 244, 5); $chart->setFontProperties("includes/tahoma.dat", 8); $chart->AntialiasQuality = 0; $chart->drawPieGraph($data->GetData(), $data->GetDataDescription(), 150, 90, 90, PIE_PERCENTAGE_LABEL, FALSE, 35, 15, 5); $chart->drawPieLegend(300, 20, $data->GetData(), $data->GetDataDescription(), 255, 255, 255); $chart->Stroke();
include "pChart/pData.class"; include "pChart/pChart.class"; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint(array(1, 4, 3, 2, 3, 3, 2, 1, 0, 7, 4, 3, 2, 3, 3, 5, 1, 0, 7), "Serie1"); $DataSet->AddPoint(array(1, 4, 2, 6, 2, 3, 0, 1, 5, 1, 2, 4, 5, 2, 1, 0, 6, 4, 2), "Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie(); $DataSet->SetSerieName("January", "Serie1"); $DataSet->SetSerieName("February", "Serie2"); // Initialise the graph $Test = new pChart(700, 230); $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(50, 30, 585, 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 cubic curve graph $Test->drawFilledCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription(), 0.1, 50); // Finish the graph $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->drawLegend(600, 30, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties("Fonts/tahoma.ttf", 10); $Test->drawTitle(50, 22, "Example 7", 50, 50, 50, 585); $Test->Stroke("example7.png");
$DataSet->AddPoint(cos($i * 3.14 / 180) * 80 + $i, "Serie1"); $DataSet->AddPoint(sin($i * 3.14 / 180) * 80 + $i, "Serie2"); } $DataSet->SetSerieName("Trigonometric function", "Serie1"); $DataSet->AddSerie("Serie1"); $DataSet->AddSerie("Serie2"); $DataSet->SetXAxisName("X Axis"); $DataSet->SetYAxisName("Y Axis"); // Initialise the graph $Test = new pChart(300, 300); $Test->drawGraphAreaGradient(0, 0, 0, -100, TARGET_BACKGROUND); // Prepare the graph area $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(55, 30, 270, 230); $Test->drawXYScale($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie1", "Serie2", 213, 217, 221, TRUE, 45); $Test->drawGraphArea(213, 217, 221, FALSE); $Test->drawGraphAreaGradient(30, 30, 30, -50); $Test->drawGrid(4, TRUE, 230, 230, 230, 20); // Draw the chart $Test->setShadowProperties(2, 2, 0, 0, 0, 60, 4); $Test->drawXYGraph($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie1", "Serie2", 0); $Test->clearShadow(); // Draw the title $Title = "Drawing X versus Y charts trigonometric functions "; $Test->drawTextBox(0, 280, 300, 300, $Title, 0, 255, 255, 255, ALIGN_RIGHT, TRUE, 0, 0, 0, 30); // Draw the legend $Test->setFontProperties("Fonts/pf_arma_five.ttf", 6); $DataSet->RemoveSerie("Serie2"); $Test->drawLegend(160, 5, $DataSet->GetDataDescription(), 0, 0, 0, 0, 0, 0, 255, 255, 255, FALSE); $Test->Stroke("example24.png");
public function componentPieChart() { $DataSet = new pData(); if (count($this->values) > 0) { $DataSet->AddPoint($this->values, "Serie1"); $DataSet->AddPoint($this->labels, "Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("Serie2"); } // Draw the pie chart // Initialise the graph $Test = new pChart($this->width, $this->height); $Test->setFontProperties(THEBUGGENIE_MODULES_PATH . 'pchart' . DS . 'fonts' . DS . 'DroidSans.ttf', 8); $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); if ($this->height > 200 && $this->width > 250) { if (count($this->values) > 0) { $Test->drawPieLegend($this->width / 3 + $this->width / 3, 40, $DataSet->GetData(), $DataSet->GetDataDescription(), 250, 250, 250); } $title_font_size = 10; $left = $this->width / 3; $pie_labels = PIE_PERCENTAGE_AND_VALUES; } else { $title_font_size = 7; $left = $this->width / 2; $pie_labels = PIE_NOLABEL; } if (isset($this->style) && $this->style == '3d' && count($this->values) > 0) { $Test->drawPieGraph($DataSet->GetData(), $DataSet->GetDataDescription(), floor($left), floor($this->height / 2), floor(($this->width + $this->height) / 6), $pie_labels, TRUE, 40, 10, 3); } $Test->setFontProperties(THEBUGGENIE_MODULES_PATH . 'pchart' . DS . 'fonts' . DS . 'DroidSansBold.ttf', $title_font_size); $Test->drawTitle(50, 22, $this->title, 50, 50, 50, $this->width - 30); $Test->Stroke(); //("example2.png"); }
// Dataset definition $DataSet = new pData(); $DataSet->AddPoint(array(10, 4, 3, 2, 3, 3, 2, 1, 0, 7, 4, 3, 2, 3, 3, 5, 1, 0, 7), "Serie1"); $DataSet->AddPoint(array(1, 4, 2, 6, 2, 3, 0, 1, -5, 1, 2, 4, 5, 2, 1, 0, 6, 4, 30), "Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie(); $DataSet->SetXAxisName("Samples"); $DataSet->SetYAxisName("Temperature"); $DataSet->SetSerieName("January", "Serie1"); // Initialise the graph $Test = new pChart(700, 230); $Test->reportWarnings("GD"); $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(60, 30, 585, 185); $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 cubic curve graph $Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription()); // Finish the graph $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->drawLegend(600, 30, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties("Fonts/tahoma.ttf", 10); $Test->drawTitle(50, 22, "Example 19", 50, 50, 50, 585); $Test->Stroke("example19.png");
exit; } else { if ($charttype == "course") { // Initialise the graph $Test = new pChart(420, 250); $Test->drawFilledRoundedRectangle(7, 7, 413, 243, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 415, 245, 5, 230, 230, 230); $Test->createColorGradientPalette(195, 204, 56, 223, 110, 41, 5); // Draw the pie chart $Test->setFontProperties($CFG->dirroot . "/local/iomad/pchart/Fonts/tahoma.ttf", 8); $Test->AntialiasQuality = 0; $Test->drawPieGraph($chartdata->GetData(), $chartdata->GetDataDescription(), 180, 130, 110, PIE_PERCENTAGE_LABEL, FALSE, 50, 20, 5); $Test->drawPieLegend(330, 15, $chartdata->GetData(), $chartdata->GetDataDescription(), 250, 250, 250); // Finish the graph $Test->setFontProperties($CFG->dirroot . "/local/iomad/pchart/Fonts/tahoma.ttf", 8); $Test->drawLegend(135, 150, $chartdata->GetDataDescription(), 255, 255, 255); $Test->setFontProperties($CFG->dirroot . "/local/iomad/pchart/Fonts/tahoma.ttf", 10); $Test->drawTitle(0, 22, "Course Completion", 50, 50, 50, 210); $Test->Stroke("SmallStacked.png"); exit; } } } if (empty($dodownload) && !empty($charttype)) { $params['showchart'] = true; echo "<center><img src='" . new moodle_url('/local/report_completion/index.php', $params) . "'></center>"; } if (!empty($dodownload)) { exit; } echo $OUTPUT->footer();
function createChart(&$info, &$cfg) { $backgndColor = array('R' => 255, 'G' => 255, 'B' => 254); $chartCfg = new stdClass(); $chartCfg->XSize = $info->canDraw ? $cfg->XSize : 600; $chartCfg->YSize = $info->canDraw ? $cfg->YSize : 50; $chartCfg->border = new stdClass(); $chartCfg->border->width = 1; $chartCfg->border->color = array('R' => 0, 'G' => 0, 'B' => 0); $chartCfg->graphArea = new stdClass(); $chartCfg->graphArea->color = array('R' => 213, 'G' => 217, 'B' => 221); $chartCfg->graphArea->beginX = property_exists($cfg, 'beginX') ? $cfg->beginX : 40; $chartCfg->graphArea->beginY = property_exists($cfg, 'beginY') ? $cfg->beginY : 100; $chartCfg->graphArea->endX = $chartCfg->XSize - $chartCfg->graphArea->beginX; $chartCfg->graphArea->endY = $chartCfg->YSize - $chartCfg->graphArea->beginY; $chartCfg->scale = new stdClass(); // 20100914 - franciscom // After reading documentation // drawScale // Today there is four way of computing scales : // // - Getting Max & Min values per serie : ScaleMode = SCALE_NORMAL // - Like the previous one but setting the min value to 0 : ScaleMode = SCALE_START0 // - Getting the series cumulative Max & Min values : ScaleMode = SCALE_ADDALL // - Like the previous one but setting the min value to 0 : ScaleMode = SCALE_ADDALLSTART0 // // This will depends on the kind of graph you are drawing, today only the stacked bar chart // can use the SCALE_ADDALL mode. // Drawing graphs were you want to fix the min value to 0 you must use the SCALE_START0 option. // $chartCfg->scale->mode = SCALE_ADDALLSTART0; $chartCfg->scale->color = array('R' => 0, 'G' => 0, 'B' => 0); $chartCfg->scale->drawTicks = TRUE; $chartCfg->scale->angle = $cfg->scale->legendXAngle; $chartCfg->scale->decimals = 1; $chartCfg->scale->withMargin = TRUE; $chartCfg->legend = new stdClass(); $chartCfg->legend->X = $chartCfg->XSize - 80; $chartCfg->legend->Y = 15; $chartCfg->legend->color = array('R' => 236, 'G' => 238, 'B' => 240); $chartCfg->title = new stdClass(); $chartCfg->title->value = $cfg->chartTitle; $chartCfg->title->X = 2 * $chartCfg->graphArea->beginX; $chartCfg->title->Y = $chartCfg->legend->Y; $chartCfg->title->color = array('R' => 0, 'G' => 0, 'B' => 255); $Test = new pChart($chartCfg->XSize, $chartCfg->YSize); $Test->reportWarnings("GD"); $Test->drawBackground($backgndColor['R'], $backgndColor['G'], $backgndColor['B']); $Test->drawGraphArea($chartCfg->graphArea->color['R'], $chartCfg->graphArea->color['G'], $chartCfg->graphArea->color['B']); $Test->setGraphArea($chartCfg->graphArea->beginX, $chartCfg->graphArea->beginY, $chartCfg->graphArea->endX, $chartCfg->graphArea->endY); $Test->setFontProperties(config_get('charts_font_path'), config_get('charts_font_size')); if ($info->canDraw) { $DataSet = new pData(); foreach ($info->chart_data as $key => $values) { $id = $key + 1; $DataSet->AddPoint($values, "Serie{$id}"); $DataSet->SetSerieName($info->series_label[$key], "Serie{$id}"); } $DataSet->AddPoint($info->xAxis->values, $info->xAxis->serieName); $DataSet->AddAllSeries(); $DataSet->RemoveSerie($info->xAxis->serieName); $DataSet->SetAbsciseLabelSerie($info->xAxis->serieName); $chartData = $DataSet->GetData(); $chartLegend = $DataSet->GetDataDescription(); foreach ($info->series_color as $key => $hexrgb) { $rgb = str_split($hexrgb, 2); $Test->setColorPalette($key, hexdec($rgb[0]), hexdec($rgb[1]), hexdec($rgb[2])); } // $Test->setFixedScale($info->scale->minY,$info->scale->maxY,$info->scale->divisions); $Test->drawScale($chartData, $chartLegend, $chartCfg->scale->mode, $chartCfg->scale->color['R'], $chartCfg->scale->color['G'], $chartCfg->scale->color['B'], $chartCfg->scale->drawTicks, $chartCfg->scale->angle, $chartCfg->scale->decimals, $chartCfg->scale->withMargin); $Test->drawStackedBarGraph($chartData, $chartLegend, 70); // Draw the legend $Test->setFontProperties(config_get('charts_font_path'), config_get('charts_font_size')); $Test->drawLegend($chartCfg->legend->X, $chartCfg->legend->Y, $chartLegend, $chartCfg->legend->color['R'], $chartCfg->legend->color['G'], $chartCfg->legend->color['B']); $Test->addBorder($chartCfg->border->width, $chartCfg->border->color['R'], $chartCfg->border->color['G'], $chartCfg->border->color['B']); } else { $chartCfg->title->value .= '/' . lang_get('no_data_available'); } $Test->drawTitle($chartCfg->title->X, $chartCfg->title->Y, $chartCfg->title->value, $chartCfg->title->color['R'], $chartCfg->title->color['G'], $chartCfg->title->color['B']); $Test->Stroke(); }
/** * Displays a chart. * * @return void */ public function get_chart() { $input = JFactory::getApplication()->input; error_reporting(E_ALL); include JPATH_COMPONENT . '/helpers/pchart/pData.class.php'; include JPATH_COMPONENT . '/helpers/pchart/pChart.class.php'; JFactory::getDocument()->setMimeEncoding('image/jpg'); $data = $input->getVar('data', ''); $labels = $input->getVar('labels', ''); $colorChart = $input->getInt('color', 8); $colorPath = JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers' . DS . 'pchart' . DS . 'colours' . DS . 'tones-' . $colorChart . '.txt'; $DataSet = new pData(); if ($data) { $data = explode(',', $data); $labels = explode(',', $labels); $DataSet->AddPoint($data, 'Serie1'); $DataSet->AddPoint($labels, 'Serie2'); } else { $DataSet->AddPoint(array(10, 2, 3, 5, 3), "Serie1"); $DataSet->AddPoint(array("Jan", "Feb", "Mar", "Apr", "May"), "Serie2"); } $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("Serie2"); //-- Initialise the graph $chart = new pChart(380, 200); if (JFile::exists($colorPath)) { $chart->loadColorPalette($colorPath); } /* $chart->drawFilledRoundedRectangle(7, 7, 373, 193, 5, 240, 240, 240); $chart->drawRoundedRectangle(5, 5, 375, 195, 5, 230, 230, 230); */ //-- Draw the pie chart $chart->setFontProperties(JPATH_COMPONENT . DS . 'helpers' . DS . 'pchart/Fonts/MankSans.ttf', 10); $chart->drawPieGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 150, 90, 110, PIE_PERCENTAGE, true, 50, 20, 5); $chart->drawPieLegend(290, 15, $DataSet->GetData(), $DataSet->GetDataDescription(), 250, 250, 250); //-- Spit it out $chart->Stroke(); return; }
// 设置作图区域 $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); ?>
public function gerarGraficoLinhas() { if (count($this->_dados[0]) < 1) { die("Algum dado deve ser passado. <br>Ex. \$grafico->setDados(array(10,20,30));"); } if (count($this->_dados[0]) != count($this->_tituloItens)) { die("A quantidade de titulos passados difere da quantidade de valores. Certifique-se de que eles estejam em igual numero."); } // Montando plotagens com os arrays de dados passados $DataSet = new pData(); // Definindo labels dos eixos if (!empty($this->_tituloEixoX)) { $DataSet->SetXAxisName($this->_tituloEixoX); $DataSet->SetYAxisName($this->_tituloEixoY); } // Montando plotagens com os arrays de dados passados for ($i = 0; $i < count($this->_dados); $i++) { $DataSet->AddPoint($this->_dados[$i], $this->_tituloDados[$i]); $DataSet->AddSerie($this->_tituloDados[$i]); //x($this->_tituloItens[$i]); } // Definindo labels dos dados if (count($this->_tituloItens) > 0) { $DataSet->AddPoint($this->_tituloItens, "labels"); $DataSet->SetAbsciseLabelSerie("labels"); } // Initialise the graph $Test = new pChart($this->_larguraGrafico * 2, $this->_alturaGrafico * 2); $Test->setFontProperties(CAMINHO_PCHART_FONT . "/tahoma.ttf", 8); $Test->setGraphArea($this->_margem * 3, $this->_margem * 2, 120 * $this->_larguraGrafico / 100, 130 * $this->_alturaGrafico / 100 - 10); $Test->drawFilledRoundedRectangle(7, 7, 150 * $this->_larguraGrafico / 100, 150 * $this->_alturaGrafico / 100, 5, $this->_corFundo["r"], $this->_corFundo["g"], $this->_corFundo["b"]); $Test->drawRoundedRectangle(5, 5, 150 * $this->_larguraGrafico / 100 + 3, 150 * $this->_alturaGrafico / 100 + 3, 5, $this->_corMargem["r"], $this->_corMargem["g"], $this->_corMargem["b"]); $Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, $this->_corLabels["r"], $this->_corLabels["g"], $this->_corLabels["b"], TRUE, $this->_anguloValores, 0, TRUE); $Test->drawGrid(4, TRUE); // Draw the 0 line $Test->setFontProperties(CAMINHO_PCHART_FONT . "/tahoma.ttf", 10); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); if ($this->_qtdeSeries <= 1 && $this->_exibirValores == true) { $Test->writeValues($DataSet->GetData(), $DataSet->GetDataDescription(), $this->_tituloDados); } // Draw the limit graph $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); // Finish the graph $Test->setFontProperties(CAMINHO_PCHART_FONT . "/tahoma.ttf", 8); $Test->drawLegend(72 * $this->_larguraGrafico / 100, 50, $DataSet->GetDataDescription(), 255, 249, 223, 15, 15, 15); $Test->setFontProperties(CAMINHO_PCHART_FONT . "/tahoma.ttf", 14); $Test->drawTitle($this->_larguraGrafico / 2 - 20, 30, $this->_tituloGrafico, $this->_corLabels["r"], $this->_corLabels["g"], $this->_corLabels["b"]); $Test->Stroke(); }
include "pChart/pChart.class"; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint(array(1079, 1151, 1185, 1226, 1121, 738, 710), "Visitor"); $DataSet->AddPoint(array("1 พ.ย.", "2 พ.ย.", "3 พ.ย.", "4 พ.ย.", "5 พ.ย.", "6 พ.ย.", "7 พ.ย."), "Day"); $DataSet->AddSerie("Visitor"); $DataSet->SetAbsciseLabelSerie("Day"); $DataSet->SetYAxisName("Visitors"); $DataSet->SetYAxisUnit("ip"); // Initialise the graph $Graph = new pChart(700, 230); $Graph->setFontProperties("Fonts/tahoma.ttf", 8); $Graph->setGraphArea(70, 30, 680, 200); $Graph->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240); $Graph->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230); $Graph->drawGraphArea(255, 255, 255, TRUE); $Graph->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2); $Graph->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the 0 line $Graph->setFontProperties("Fonts/tahoma.ttf", 6); $Graph->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the line graph $Graph->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); $Graph->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255); // Finish the graph $Graph->setFontProperties("Fonts/tahoma.ttf", 8); $Graph->drawLegend(75, 35, $DataSet->GetDataDescription(), 255, 255, 255); $Graph->setFontProperties("Fonts/tahoma.ttf", 10); $Graph->drawTitle(60, 22, "Google Analytics", 50, 50, 50, 585); $Graph->Stroke("example1.png");
foreach ($plot as $k => $v) { if (isset($v["legend"]) && $v["legend"]) { // Temporarily Dont draw legend for Pie //if ( $piechart ) //$graphImage->drawPieLegend($width - 180,30,$graphData->GetData(), $graphData->GetDataDescription(), 250, 250, 250); if (!$piechart) { $graphImage->drawLegend($width - 180, 30, $graphData->GetDataDescription(), 254, 254, 254, 0, 0, 0); } break; } } $graphImage->setFontProperties(PCHARTFONTS_DIR . $xtitlefont, $titlefontsize); $graphImage->drawTitle(0, 24, $title, 50, 50, 50, $width); //$graphImage->setShadow(TRUE,array("X"=>0,"Y"=>0,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); //$graphImage->Render("example.png"); $graphImage->Stroke(); function minmaxValueOfSeries($data, &$min, &$max) { $min = "undef"; $max = "undef"; foreach ($data as $v) { if ($min == "undef" || $v < $min) { $min = $v; } if ($max == "undef" || $v > $max) { $max = $v; } } } function disableAllSeries($plot, &$graphData) {
/** * Does the magic. Creates all necessary stuff and finally * sends the graph directly (!!!) to the browser. * Execution should be terminated afterwards. * */ public function showGraph() { $this->preGraphCreation(); $this->objChart->Stroke(); }
$DataSet = new pData; $DataSet->AddPoint($series[1], "Serie1"); // Invert/Reverse Hebrew labels so it can be rendered using PHP imagettftext() foreach ($series[0] as $key => $value) { $invertedlabels[$key] = strip_tags((preg_match("/[\xE0-\xFA]/", iconv("UTF-8", "ISO-8859-8", $value))) ? $reportclass->utf8_strrev($value) : $value); } $DataSet->AddPoint($invertedlabels /* $series[0] */, "Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("Serie2"); // Initialise the graph $Test = new pChart(450, 200 + (count($series[0]) * 10)); $Test->drawFilledRoundedRectangle(7, 7, 293, 193, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 295, 195, 5, 230, 230, 230); $Test->createColorGradientPalette(195, 204, 56, 223, 110, 41, 5); // Draw the pie chart $Test->setFontProperties($CFG->dirroot . "/blocks/cobalt_reports/lib/Fonts/tahoma.ttf", 8); $Test->AntialiasQuality = 0; //$Test->drawFlatPieGraph($DataSet->GetData(),$DataSet->GetDataDescription(),120,100,60,TRUE,10); //$Test->drawBasicPieGraph($DataSet->GetData(),$DataSet->GetDataDescription(),120,100,70,PIE_PERCENTAGE,255,255,218); $Test->drawPieGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 150, 90, 110, PIE_PERCENTAGE, TRUE, 50, 20, 5); $Test->drawPieLegend(300, 15, $DataSet->GetData(), $DataSet->GetDataDescription(), 250, 250, 250); ob_clean(); // Hack to clear output and send only IMAGE data to browser $Test->Stroke(); } } }
function createChart(&$info, &$cfg) { $backgndColor = array('R' => 255, 'G' => 255, 'B' => 254); $chartCfg = new stdClass(); $chartCfg->XSize = $info->canDraw ? $cfg->XSize : 600; $chartCfg->YSize = $info->canDraw ? $cfg->YSize : 50; $chartCfg->border = new stdClass(); $chartCfg->border->width = 1; $chartCfg->border->color = array('R' => 0, 'G' => 0, 'B' => 0); $chartCfg->graphArea = new stdClass(); $chartCfg->graphArea->color = array('R' => 213, 'G' => 217, 'B' => 221); $chartCfg->graphArea->beginX = 40; $chartCfg->graphArea->beginY = 40; $chartCfg->graphArea->endX = $chartCfg->XSize - $chartCfg->graphArea->beginX; $chartCfg->graphArea->endY = $chartCfg->YSize - $chartCfg->graphArea->beginY; $chartCfg->scale = new stdClass(); $chartCfg->scale->mode = SCALE_ADDALL; $chartCfg->scale->color = array('R' => 0, 'G' => 0, 'B' => 0); $chartCfg->scale->drawTicks = TRUE; $chartCfg->scale->angle = $cfg->scale->legendXAngle; $chartCfg->scale->decimals = 1; $chartCfg->scale->withMargin = TRUE; $chartCfg->legend = new stdClass(); $chartCfg->legend->X = $chartCfg->XSize - 80; $chartCfg->legend->Y = 15; $chartCfg->legend->color = array('R' => 236, 'G' => 238, 'B' => 240); $chartCfg->title = new stdClass(); $chartCfg->title->value = $cfg->chartTitle; $chartCfg->title->X = 2 * $chartCfg->graphArea->beginX; $chartCfg->title->Y = $chartCfg->legend->Y; $chartCfg->title->color = array('R' => 0, 'G' => 0, 'B' => 255); $Test = new pChart($chartCfg->XSize, $chartCfg->YSize); $Test->drawBackground($backgndColor['R'], $backgndColor['G'], $backgndColor['B']); $Test->drawGraphArea($chartCfg->graphArea->color['R'], $chartCfg->graphArea->color['G'], $chartCfg->graphArea->color['B']); $Test->setGraphArea($chartCfg->graphArea->beginX, $chartCfg->graphArea->beginY, $chartCfg->graphArea->endX, $chartCfg->graphArea->endY); $Test->setFontProperties(config_get('charts_font_path'), config_get('charts_font_size')); if ($info->canDraw) { $DataSet = new pData(); foreach ($info->chart_data as $key => $values) { $id = $key + 1; $DataSet->AddPoint($values, "Serie{$id}"); $DataSet->SetSerieName($info->series_label[$key], "Serie{$id}"); } $DataSet->AddPoint($info->xAxis->values, $info->xAxis->serieName); $DataSet->AddAllSeries(); $DataSet->RemoveSerie($info->xAxis->serieName); $DataSet->SetAbsciseLabelSerie($info->xAxis->serieName); $chartData = $DataSet->GetData(); $chartLegend = $DataSet->GetDataDescription(); foreach ($info->series_color as $key => $hexrgb) { $rgb = str_split($hexrgb, 2); $Test->setColorPalette($key, hexdec($rgb[0]), hexdec($rgb[1]), hexdec($rgb[2])); } // $Test->setFixedScale($info->scale->minY,$info->scale->maxY,$info->scale->divisions); $Test->drawScale($chartData, $chartLegend, $chartCfg->scale->mode, $chartCfg->scale->color['R'], $chartCfg->scale->color['G'], $chartCfg->scale->color['B'], $chartCfg->scale->drawTicks, $chartCfg->scale->angle, $chartCfg->scale->decimals, $chartCfg->scale->withMargin); $Test->drawStackedBarGraph($chartData, $chartLegend, 70); // Draw the legend $Test->setFontProperties(config_get('charts_font_path'), config_get('charts_font_size')); $Test->drawLegend($chartCfg->legend->X, $chartCfg->legend->Y, $chartLegend, $chartCfg->legend->color['R'], $chartCfg->legend->color['G'], $chartCfg->legend->color['B']); $Test->addBorder($chartCfg->border->width, $chartCfg->border->color['R'], $chartCfg->border->color['G'], $chartCfg->border->color['B']); } else { $chartCfg->title->value .= '/' . lang_get('no_data_available'); } $Test->drawTitle($chartCfg->title->X, $chartCfg->title->Y, $chartCfg->title->value, $chartCfg->title->color['R'], $chartCfg->title->color['G'], $chartCfg->title->color['B']); $Test->Stroke(); }