/** * Draw pie chart * @return unknown */ protected function drawPie() { // 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 $pie_x = intval(($this->w - 150) / 2); // Pie witdh $pie_y = intval(($this->h - 10) / 2); // Pie heigth $pie_r = intval($pie_x - 50); // Pie radius $title_w = $this->w - 200; // Title width $title_h = 50; // Title height $legend_w = $this->w - 120; // Legend width $legend_h = 50; // Legend height // chart styles $flat = isset($this->p['flat']) ? $this->p['flat'] : 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) // draw the pie chart $this->chart->setFontProperties($this->font, 8); // flat pie if ($flat) { $this->chart->drawFlatPieGraphWithShadow($this->data->GetData(), $this->data->GetDataDescription(), $pie_x, $pie_y, $pie_r, PIE_PERCENTAGE, 10); // 3d pie } else { $this->chart->drawPieGraph($this->data->GetData(), $this->data->GetDataDescription(), $pie_x, $pie_y, $pie_r, PIE_PERCENTAGE, TRUE, 50, 20, 5, 1); } $this->chart->drawPieLegend($legend_w, $legend_h, $this->data->GetData(), $this->data->GetDataDescription(), 250, 250, 250); // 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) }
// Standard inclusions 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->Render("example7.png");
public function _showGraph_pChart($buscarBarra) { // Dataset definition $DataSet = new pData(); if ($buscarBarra == "semana") { $semana = array("1era Semana", "2da Semana", "3era Semana", "4ta Semana"); $cantidadSemanal = array(2, 4, 5, 6); $DataSet->AddPoint($semana, "Serie1"); $DataSet->AddPoint($cantidadSemanal, "Serie2"); // Initialise the graph define("WIDTH", 500); define("HEIGHT", 500); $Test = new pChart(WIDTH, HEIGHT); $Test->setFontProperties("../font/arial.ttf", 7); $Test->setGraphArea(40, 30, WIDTH - 30, HEIGHT - 30); $Test->drawFilledRoundedRectangle(7, 7, WIDTH - 7, HEIGHT - 7, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, WIDTH - 5, HEIGHT - 5, 5, 230, 230, 230); } elseif ($buscarBarra == "mes") { $mensual = array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Setiembre", "Octubre"); $cantidadMensual = array(4, 6, 11, 23, 9, 2, 30, 20, 12, 45); $DataSet->AddPoint($mensual, "Serie1"); $DataSet->AddPoint($cantidadMensual, "Serie2"); // Initialise the graph define("WIDTH", 700); define("HEIGHT", 500); $Test = new pChart(WIDTH, HEIGHT); $Test->setFontProperties("../font/arial.ttf", 7); $Test->setGraphArea(40, 30, WIDTH - 30, HEIGHT - 30); $Test->drawFilledRoundedRectangle(7, 7, WIDTH - 7, HEIGHT - 7, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, WIDTH - 5, HEIGHT - 5, 5, 230, 230, 230); $Test->setColorPalette(0, 224, 100, 46); } $DataSet->AddAllSeries(); $DataSet->RemoveSerie("Serie1"); $DataSet->SetAbsciseLabelSerie("Serie1"); $DataSet->SetSerieName("Productos Comprados", "Serie2"); // Initialise the graph $Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 0, 2, TRUE); $Test->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the 0 line $Test->setFontProperties("../font/arial.ttf", 6); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the bar graph $Test->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 70); // Set labels $Test->setFontProperties("../font/arial.ttf", 7); $Test->writeValues($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie2"); // Finish the graph $Test->setFontProperties("../font/arial.ttf", 8); $Test->drawLegend(WIDTH / 5, 25, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties("../font/arial.ttf", 10); $Test->drawTitle(WIDTH - 200, 22, "Estadistica de Barra de Grafico", 50, 50, 50, 185); $Test->Render("../img/imagenBarra_pChart.png"); }
function bar($valores, $label, $titulo) { $nombre = tempnam('/tmp', 'g') . '.png'; $DataSet = new pData(); foreach ($valores as $ind => $val) { $DataSet->AddPoint(array($val), 'Serie' . $ind); $DataSet->SetSerieName($label[$ind], 'Serie' . $ind); } $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie(); $Test = new pChart(300, 200); $Test->setFontProperties(APPPATH . 'libraries/pChart/Fonts/tahoma.ttf', 8); $Test->setGraphArea(60, 40, 250, 180); $Test->drawFilledRoundedRectangle(7, 7, 293, 193, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 295, 195, 5, 230, 230, 230); $Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, true, 0, 0); $Test->drawGrid(4, TRUE, 200, 200, 200, 50); $Test->setFontProperties(APPPATH . 'libraries/pChart/Fonts/tahoma.ttf', 6); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE); //$Test->drawOverlayBarGraph($DataSet->GetData(),$DataSet->GetDataDescription()); $Test->setFontProperties(APPPATH . 'libraries/pChart/Fonts/tahoma.ttf', 8); $Test->drawLegend(220, 7, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties(APPPATH . 'libraries/pChart/Fonts/tahoma.ttf', 10); $Test->drawTitle(10, 22, $titulo, 50, 50, 50, 300); $Test->Render($nombre); return $nombre; }
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(); }
/** * Генерация графика * @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 generateGraph($year, $month, $quarter, $biAnn, $dev, $patna, $duration, $from, $to) { $myarr = graphTests($year, $month, $quarter, $biAnn, $dev, $patna, $duration, $from, $to); $myarr1 = graphErrs($year, $month, $quarter, $biAnn, $dev, $patna, $duration, $from, $to); $myarr2 = graphLbls($year, $month, $quarter, $biAnn, $dev, $patna, $duration, $from, $to); // Standard inclusions include "pChart/pChart/pData.class"; include "pChart/pChart/pChart.class"; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint($myarr, "Serie1"); $DataSet->AddPoint($myarr1, "Serie2"); $DataSet->AddPoint($myarr2, "Serie3"); $DataSet->AddSerie("Serie1"); $DataSet->AddSerie("Serie2"); $DataSet->SetAbsciseLabelSerie("Serie3"); $DataSet->SetSerieName("Test Resulting trends", "Serie1"); $DataSet->SetSerieName("Errors in tests", "Serie2"); $DataSet->SetYAxisName("Tests"); // $DataSet->SetYAxisFormat("time"); $DataSet->SetXAxisName("months"); // Initialise the graph $Test = new pChart(750, 330); $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(85, 30, 650, 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 line graph $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255); // Finish the graph $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->drawLegend(90, 35, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties("Fonts/tahoma.ttf", 10); $Test->drawTitle(60, 22, "Test Summary", 50, 50, 50, 585); $Test->Render("mpdf.png"); }
public function make($working_path) { // This will import the file http://my.domain.com/myData.csv using each column as a serie if (!$this->plot->valid()) { $file = $this->plot->name(); $error = $this->plot->error(); $this->log($working_path, "Plot file {$file} is invalid: {$error}"); return 1; } $data = new pData(); $columns = array(); $all_columns = array(); $x_column = $this->plot->property('x_column') - 1; if ($x_column === NULL) { $x_column = 0; } $data_file = $this->plot->data_property('name'); $deliminator = $this->plot->data_property('deliminator'); $has_header = $this->plot->data_property('header') == 'yes'; foreach ($this->plot->columns() as $column => $name) { if ($column != $x_column + 1) { $columns[] = $column - 1; } $all_columns[] = $column - 1; } $data->ImportFromCSV($working_path . $data_file, $deliminator, $all_columns, $has_header); foreach ($columns as $column) { $name = $this->plot->column($column + 1); $data->AddSerie('Serie' . $column); $data->SetSerieName($name, "Serie" . $column); } $max_col = -1; $max_val = NULL; foreach ($data->GetData() as $record) { foreach ($columns as $column) { $point = $record['Serie' . $column]; if ($max_val === NULL || $point > $max_val) { $max_val = $point; $max_col = $column; } } } $x_label = $this->plot->axis_property('x', 'label'); if ($x_label) { $data->SetXAxisName($x_label); } else { $data->SetXAxisName($this->plot->column($x_column + 1)); } $x_unit = $this->plot->axis_property('x', 'unit'); if ($x_unit) { $data->SetXAxisUnit($x_unit); } $y_label = $this->plot->axis_property('y', 'label'); reset($columns); if ($y_label) { $data->SetYAxisName($y_label); } else { $data->SetYAxisName($this->plot->column(current($columns) + 1)); } $y_unit = $this->plot->axis_property('y', 'unit'); if ($y_unit) { $data->SetyAxisUnit($y_unit); } $width = $this->plot->property('width'); if (!$width) { $width = 640; } $height = $this->plot->property('height'); if (!$height) { $height = 480; } $plot = new pChart($width, $height); $font_name = $this->plot->property('font-name'); if (!$font_name) { $font_name = 'tahoma.ttf'; } $font_name = 'lib/plugins/projects/pchart/fonts/' . $font_name; $font_size = $this->plot->property('font_size'); if (!$font_size) { $font_size = 12; } $plot->setFontProperties($font_name, $font_size); $h = $font_size + 10; $left_margin = 0; foreach ($data->GetData() as $record) { $position = imageftbbox($font_size, 0, $font_name, $record['Serie' . $max_col]); $text_width = $position[2] - $position[0]; if ($text_width > $left_margin) { $left_margin = $text_width; } } $left_margin += 2 * $h; $plot->setGraphArea($left_margin, 2 * $h, $width - $h, $height - 2 * $h); $background = $this->plot->property('background'); if (!$background) { $background = array('R' => 255, 'G' => 255, 'B' => 255); } else { $background = html_color_to_RGB($background); } $plot->drawGraphArea($background['R'], $background['G'], $background['B']); // pick the largest scale $plot->drawXYScale($data->GetData(), $data->GetDataDescription(), 'Serie' . $max_col, 'Serie' . $x_column, 0, 0, 0, TRUE, 0, 0); $line_no = 0; $colors = array(); foreach ($columns as $column) { $name = $this->plot->column($column + 1); $style = $this->plot->line_style($name, 'style'); $line_color = $this->plot->line_style($name, 'color'); if (!$line_color) { $colors[$name] = array('R' => 0, 'G' => 0, 'B' => 0); } else { $colors[$name] = html_color_to_RGB($line_color); } $plot->setColorPalette($line_no, $colors[$name]['R'], $colors[$name]['G'], $colors[$name]['B']); if (!$style || $style == 'line' || $style == 'both') { $line_width = $this->plot->line_style($name, 'width'); if (!$line_width) { $line_width = 1; } $dot_size = $this->plot->line_style($name, 'dot-size'); if (!$dot_size) { $dot_size = 0; } $plot->setLineStyle($line_width, $dot_size); $plot->drawXYGraph($data->GetData(), $data->GetDataDescription(), 'Serie' . $column, 'Serie' . $x_column, $line_no); } if ($style == 'point' || $style == 'both') { $radius = $this->plot->line_style($name, 'radius'); if (!$radius) { $radius = 5; } $plot->drawXYPlotGraph($data->GetData(), $data->GetDataDescription(), 'Serie' . $column, 'Serie' . $x_column, $line_no, $radius, $radius - 2); } $line_no++; } $title = $this->plot->property('title'); foreach ($columns as $column) { $data->removeSerie('Serie' . $column); } $in_legend = array(); $description = $data->GetDataDescription(); $description['Description'] = array(); $palette_id = 0; foreach ($columns as $column) { $name = $this->plot->column($column + 1); if (in_array($name, $in_legend)) { continue; } $in_legend[] = $name; $description['Description']['Serie' . $column] = $name; $plot->setColorPalette($palette_id, $colors[$name]['R'], $colors[$name]['G'], $colors[$name]['B']); ++$palette_id; } $legend_box_size = $plot->getLegendBoxSize($description); $legend_position = $this->plot->property('legend-position'); if (!$legend_position) { $legend_position = 'top-left'; } switch ($legend_position) { case 'top-left': $legend_left = 0; $legend_top = 0; break; case 'top': $legend_left = ($width - $h - $left_margin - $legend_box_size[0]) / 2; $legend_top = 0; break; case 'top-right': $legend_left = $width - $left_margin - $h - $legend_box_size[0]; $legend_top = 0; break; case 'left': $legend_left = 0; $legend_top = ($height - 4 * $h - $legend_box_size[1]) / 2; break; case 'center': $legend_left = ($width - $h - $left_margin - $legend_box_size[0]) / 2; $legend_top = ($height - 4 * $h - $legend_box_size[1]) / 2; break; case 'right': $legend_left = $width - $left_margin - $h - $legend_box_size[0]; $legend_top = ($height - 4 * $h - $legend_box_size[1]) / 2; break; case 'bottom-left': $legend_left = 0; $legend_top = $height - 4 * $h - $legend_box_size[1]; break; case 'bottom': $legend_left = ($width - $h - $left_margin - $legend_box_size[0]) / 2; $legend_top = $height - 4 * $h - $legend_box_size[1]; break; case 'bottom-right': $legend_left = $width - $left_margin - $h - $legend_box_size[0]; $legend_top = $height - 4 * $h - $legend_box_size[1]; break; } $plot->drawLegend($left_margin + $legend_left, 2 * $h + $legend_top, $description, 255, 255, 255, 100, 100, 100, 0, 0, 0, true); $plot->drawTitle($h, 0, $title, 0, 0, 0, $width - $h, $h * 2, 100); $plot->Render($this->path($working_path)); $file_name = $this->plot->name(); $plot_name = $this->name(); $this->log($working_path, "Successfully plotted {$file_name} as {$plot_name}\ntitle: {$title}\n"); return 0; }
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; }
/** * Create graph (a .png file) * * @param string $file */ public function generateGraph($file) { $patientValues = Storage::getInstance()->getPatientsData($file); /* * pGraph work */ $dataSet = new pData(); if (!empty($patientValues)) { $dataSet->AddPoint(array_keys($patientValues[$file]), 'label'); $dataSet->SetAbsciseLabelSerie('label'); $serie1 = array_values($patientValues[$file]); $average = round(array_sum($serie1) / count($serie1), 2); $dataSet->AddPoint($serie1, "Serie1"); $dataSet->AddSerie("Serie1"); // Initialise the graph $graph = new MyHorBar(450, 600); $graph->setFontProperties($this->fontsPath . '/tahoma.ttf', 8); $graph->setGraphArea(120, 60, 410, 550); $graph->drawFilledRoundedRectangle(7, 7, 443, 593, 5, 240, 240, 240); $graph->drawRoundedRectangle(5, 5, 443, 595, 5, 230, 230, 230); $graph->drawGraphArea(255, 255, 255, true); $graph->drawHorScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, true, 0, 2, true); $graph->drawHorGrid(10, true, 230, 230, 230, 50); // Draw the 0 line $graph->setFontProperties($this->fontsPath . '/tahoma.ttf', 6); $graph->drawTreshold($average, 143, 55, 72, true, false, 2, null, 90); // Draw the bar graph $graph->drawHorBarGraph($dataSet->GetData(), $dataSet->GetDataDescription(), false); // Finish the graph $graph->setFontProperties($this->fontsPath . '/tahoma.ttf', 10); $graph->drawLegend(15, 15, $dataSet->GetDataDescription(), 255, 255, 255); $graph->setFontProperties($this->fontsPath . '/tahoma.ttf', 10); $graph->drawTitle(170, 27, $file, 50, 50, 50, -1); } else { $graph = new pChart(450, 150); $graph->setGraphArea(120, 60, 410, 100); $graph->drawFilledRoundedRectangle(7, 7, 443, 143, 5, 240, 240, 240); $graph->drawRoundedRectangle(5, 5, 443, 145, 5, 230, 230, 230); $graph->setFontProperties($this->fontsPath . '/tahoma.ttf', 10); $graph->drawTitle(170, 27, $file, 50, 50, 50, -1); $graph->setFontProperties($this->fontsPath . '/tahoma.ttf', 36); $graph->drawTitle(125, 90, 'No data!', 245, 50, 50, -1); } $graph->Render(WWW_DIR . '/images/graphs/' . $file . '.png'); }
function writeBarData($data, $graph) { if ($data != "") { echo "Plottong " . $graph . "\n"; $dataset1 = array(); $dataset2 = array(); $counter = 0; $toggle = true; $data = array_reverse($data, TRUE); ksort($data); foreach ($data as $key => $value) { if ($counter % 5 != 0) { $key = " "; } array_push($dataset1, $key); array_push($dataset2, $value); $counter++; } // Dataset definition $DataSet = new pData(); $DataSet->AddPoint($dataset2, "Serie1"); $DataSet->AddPoint($dataset1, "XLabel"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("XLabel"); $DataSet->RemoveSerie("XLabel"); $DataSet->SetSerieName("Membership", "Serie1"); // Initialise the graph $Test = new pChart(700, 230); $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(50, 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, 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->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE); // Finish the graph $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->drawLegend(596, 150, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties("Fonts/tahoma.ttf", 10); $Test->drawTitle(50, 22, "Membership by Month", 50, 50, 50, 585); $Test->Render("{$graph}-bar.png"); } }
function generate_image($site_name, $visits) { $font = APP_PATH . "libs/pchart/Fonts/tahoma.ttf"; //$font = APP_PATH."includes/pchart/Fonts/DejaVuSans.ttf"; global $lang; // Dataset definition $DataSet = new pData(); $names = array(); $points = array(); foreach ($visits as $date => $visit) { $points[] = $visit; $text = $lang['days'][date('N', strtotime($date))]; $names[] = $text; } $DataSet->AddPoint($points, "Lankytojai"); $DataSet->AddPoint($names, "days"); $DataSet->AddAllSeries(); $DataSet->RemoveSerie("days"); $DataSet->SetAbsciseLabelSerie('days'); // Initialise the graph $Test = new pChart(700, 230); $Test->setFontProperties($font, 8); $Test->setGraphArea(50, 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, TRUE); $Test->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the 0 line $Test->setFontProperties($font, 6); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the bar graph $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE, 80); // Finish the graph $Test->setFontProperties($font, 8); // $Test->drawLegend(100,20,$DataSet->GetDataDescription(),255,255,255); $Test->drawLegend(610, 10, $DataSet->GetDataDescription(), 236, 238, 240, 52, 58, 82); $Test->setFontProperties($font, 10); $Test->drawTitle(50, 22, $site_name, 50, 50, 50, 585); $path = IMAGE_PATH . "{$site_name}.png"; if (file_exists($path)) { unlink($path); } $Test->Render($path); return $path; }
$Test->drawGrid(4, TRUE, 230, 230, 230, 10); $Test->setShadowProperties(3, 3, 0, 0, 0, 30, 4); $Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription()); $Test->clearShadow(); $Test->drawFilledCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription(), 0.1, 30); $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255); // Clear the scale $Test->clearScale(); // Draw the 2nd graph /*$DataSet->RemoveSerie("Serie1"); $DataSet->AddSerie("Serie2"); $DataSet->SetYAxisName("Web Hits"); $Test->drawRightScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,213,217,221,TRUE,0,0); $Test->drawGrid(4,TRUE,230,230,230,10); $Test->setShadowProperties(3,3,0,0,0,30,4); $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription()); $Test->clearShadow(); $Test->drawFilledCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription(),.1,30); $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255); */ // Write the legend (box less) $Test->setFontProperties("../Fonts/tahoma.ttf", 8); $Test->drawLegend(530, 5, $DataSet->GetDataDescription(), 0, 0, 0, 0, 0, 0, 255, 255, 255, FALSE); // Write the title $Test->setFontProperties("../Fonts/tahoma.ttf", 18); $Test->setShadowProperties(1, 1, 0, 0, 0); $Test->drawTitle(0, 0, "Comparison of Fuel usage in 2015", 255, 255, 255, 660, 30, TRUE); $Test->clearShadow(); // Render the picture $Test->Render("clientsGraph.png"); ?>
$DataSet->AddPoint($array_to_display, "Serie1"); $DataSet->AddPoint(array("Jan", "Fev", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Sept.", "Oct.", "Nov.", "Dec."), "Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("Serie2"); $DataSet->SetSerieName("{$machine_to_display}", "Serie1"); $DataSet->SetXAxisName("Mois"); $DataSet->SetYAxisName("temps par panne"); $DataSet->SetYAxisUnit(" min"); // Initialise the graph $Test = new pChart(500, 250); $Test->setFontProperties("../../pChart/Fonts/tahoma.ttf", 10); $Test->setGraphArea(85, 30, 480, 200); $Test->drawFilledRoundedRectangle(7, 7, 493, 243, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 495, 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("../../pChart/Fonts/tahoma.ttf", 10); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the line graph $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255); $Test->writeValues($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie1"); // Finish the graph $Test->setFontProperties("../../pChart/Fonts/tahoma.ttf", 8); //$Test->drawLegend(75,35,$DataSet->GetDataDescription(),255,255,255); $Test->setFontProperties("../../pChart/Fonts/tahoma.ttf", 10); $Test->drawTitle(60, 22, "Temps moyen par panne par mois", 50, 50, 50, 585); //$Test->Render("example1.png"); $Test->stroke();
} // Draw Legend if legend value has been set $drawlegend = false; 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; } }
<?php /* Naked: Naked and easy! */ // Standard inclusions 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)); $DataSet->AddSerie(); $DataSet->SetSerieName("Sample data", "Serie1"); // Initialise the graph $Test = new pChart(700, 230); $Test->setFontProperties("Fonts/tahoma.ttf", 10); $Test->setGraphArea(40, 30, 680, 200); $Test->drawGraphArea(252, 252, 252, TRUE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2); $Test->drawGrid(4, TRUE, 230, 230, 230, 70); // Draw the line graph $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255); // Finish the graph $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->drawLegend(45, 35, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties("Fonts/tahoma.ttf", 10); $Test->drawTitle(60, 22, "My pretty graph", 50, 50, 50, 585); $Test->Render("Naked.png");
public function testDrawArea() { // Dataset definition $DataSet = new pData(); $DataSet->addPoints(array(10, 9.4, 7.7, 5, 1.7, -1.7, -5, -7.7, -9.4, -10, -9.4, -7.7, -5, -1.8, 1.7), "Serie1"); $DataSet->addPoints(array(0, 3.4, 6.4, 8.699999999999999, 9.800000000000001, 9.800000000000001, 8.699999999999999, 6.4, 3.4, 0, -3.4, -6.4, -8.6, -9.800000000000001, -9.9), "Serie2"); $DataSet->addPoints(array(7.1, 9.1, 10, 9.699999999999999, 8.199999999999999, 5.7, 2.6, -0.9, -4.2, -7.1, -9.1, -10, -9.699999999999999, -8.199999999999999, -5.8), "Serie3"); $DataSet->addPoints(array("Jan", "Jan", "Jan", "Feb", "Feb", "Feb", "Mar", "Mar", "Mar", "Apr", "Apr", "Apr", "May", "May", "May"), "Serie4"); $DataSet->AddAllSeries(); $DataSet->SetAbscissaLabelSeries("Serie4"); $DataSet->SetSeriesName("Max Average", "Serie1"); $DataSet->SetSeriesName("Min Average", "Serie2"); $DataSet->SetSeriesName("Temperature", "Serie3"); $DataSet->SetYAxisName("Temperature"); $DataSet->SetXAxisName("Month of the year"); // Initialise the graph $canvas = new TestCanvas(); $Test = new pChart(700, 230, $canvas); $Test->reportWarnings("GD"); $Test->setFixedScale(-12, 12, 5); $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(65, 30, 570, 185); $canvas->drawFilledRoundedRectangle(new Point(7, 7), new Point(693, 223), 5, new Color(240), 1, 0, ShadowProperties::NoShadow()); $backgroundStyle = new BackgroundStyle(new Color(255), TRUE); $Test->drawGraphBackground($backgroundStyle); $scaleStyle = new ScaleStyle(SCALE_NORMAL, new Color(150)); $Test->drawScale($DataSet, $scaleStyle, 0, 2, TRUE, 3); $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 area $DataSet->RemoveSeries("Serie4"); $Test->drawArea($DataSet->GetData(), "Serie1", "Serie2", new Color(239, 238, 227), 50); $DataSet->RemoveSeries("Serie3"); $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); // Draw the line graph $Test->setLineStyle(1, 6); $DataSet->RemoveAllSeries(); $DataSet->AddSeries("Serie3"); $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, new Color(255)); // Write values on Serie3 $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->writeValues($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie3"); // Finish the graph $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->drawLegend(590, 90, $DataSet->GetDataDescription(), new Color(255)); $Test->setFontProperties("Fonts/tahoma.ttf", 10); $Test->drawTitle(60, 22, "example 15", new Color(50), 585); // Add an image $Test->drawFromPNG(dirname(__FILE__) . "/../Sample/logo.png", 584, 35); $this->assertEquals('53b34d556af518230b7556e19349bd94', md5($canvas->getActionLog())); }
<?php /* Example10 : A 3D exploded pie graph */ // Standard inclusions require_once "../pChart/pData.class"; require_once "../pChart/pChart.class"; // Dataset definition $DataSet = new pData(); $data = array(10, 2, 3, 5, 3, 11, 13, 12, 11, 15, 5, 16); $sum = array_sum($data); $DataSet->AddPoint($data, "Serie1"); $DataSet->AddPoint(array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"), "Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("Serie2"); // Initialise the graph $Test = new pChart(420, 250); $Test->drawFilledRoundedRectangle(7, 7, 413, 243, 5, 210, 200, 240); $Test->drawRoundedRectangle(5, 5, 415, 245, 5, 0, 230, 230); $Test->createColorGradientPalette(195, 204, 56, 223, 110, 41, 5); // Draw the pie chart $Test->setFontProperties("../Fonts/tahoma.ttf", 8); $Test->AntialiasQuality = 0; $Test->drawPieGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 180, 130, 110, PIE_PERCENTAGE_LABEL, FALSE, 50, 20, 5); $Test->drawPieLegend(330, 15, $DataSet->GetData(), $DataSet->GetDataDescription(), 250, 250, 250); // Write the title $Test->setFontProperties("../Fonts/tahoma.ttf", 13); $Test->drawTitle(10, 20, "Firewood Usage in 2015", 114, 16, 46); $Test->drawTitle(320, 220, 'Total :' . $sum . 'kg', 224, 46, 147); $Test->Render("firewood.png");
function generate_graph_image($outputfile) { // Create Graph Dataset and set axis attributes $graphData = new pData(); $graphData->setYAxisName($this->ytitle); $graphData->AddPoint($this->xlabels, "xaxis"); //$graphData->SetSerieName("xaxis","xaxis"); $graphData->SetAbsciseLabelSerie("xaxis"); $graphData->setXAxisName($this->xtitle); // Add each series of plot values to dataset, but Reportico will // duplicate series were the same data are displayed in different forms // so only add each unique series once $seriesadded = array(); foreach ($this->plot as $k => $v) { $series = $v["name"] . $k; $graphData->AddPoint($v["data"], $series); $graphData->SetSerieName($v["legend"], $series); $graphData->AddSerie($series); } /* switch ( $this->xgriddisplay ) { case "all": $graph->xgrid->Show(true,true); break; case "major": $graph->xgrid->Show(true,false); break; case "minor": $graph->xgrid->Show(false,true); break; case "none": default: $graph->xgrid->Show(false,false); break; } switch ( $this->ygriddisplay ) { case "all": $graph->ygrid->Show(true,true); break; case "major": $graph->ygrid->Show(true,false); break; case "minor": $graph->ygrid->Show(false,true); break; case "none": default: $graph->ygrid->Show(false,false); break; } */ /* $graph->xaxis->SetFont($fontfamilies[$xaxisfont],$fontstyles[$xaxisfontstyle], $xaxisfontsize); $graph->xaxis->SetColor($xaxiscolor,$xaxisfontcolor); $graph->yaxis->SetFont($fontfamilies[$yaxisfont],$fontstyles[$yaxisfontstyle], $yaxisfontsize); $graph->yaxis->SetColor($yaxiscolor,$yaxisfontcolor); $graph->xaxis->title->SetFont($fontfamilies[$xtitlefont],$fontstyles[$xtitlefontstyle], $xtitlefontsize); $graph->xaxis->title->SetColor($xtitlecolor); $graph->yaxis->title->SetFont($fontfamilies[$ytitlefont],$fontstyles[$ytitlefontstyle], $ytitlefontsize); $graph->yaxis->title->SetColor($ytitlecolor); $graph->xaxis->SetLabelAngle(90); $graph->xaxis->SetLabelMargin(15); $graph->yaxis->SetLabelMargin(15); $graph->xaxis->SetTickLabels($this->xlabels); $graph->xaxis->SetTextLabelInterval($xticklabint); $graph->yaxis->SetTextLabelInterval($yticklabint); $graph->xaxis->SetTextTickInterval($xtickinterval); $graph->yaxis->SetTextTickInterval($ytickinterval); */ /* if ( $gridpos == "front" ) $graph->SetGridDepth(DEPTH_FRONT); */ // Display the graph /*?$graph->Stroke();*/ $this->apply_defaults_internal(); //echo $this->width_pdf_actual.",".$this->height_pdf_actual."<BR>"; $graphImage = new pChart($this->width_pdf_actual, $this->height_pdf_actual); /* Turn of Antialiasing */ $graphImage->Antialias = TRUE; // Add gradient fill from chosen background color to white $startgradient = htmltorgb("#ffffff"); //$graphImage->drawGradientArea(0,0,$width,$height,DIRECTION_VERTICAL,array( //"StartR"=>$startgradient[0], "StartG"=>$startgradient[1], "StartB"=>$startgradient[2], //"EndR"=>$color[0], "EndG"=>$color[1], "EndB"=>$color[2],"Alpha"=>100)); /* Add a border to the picture */ //$graphImage->drawRectangle(0,0,$width - 1,$height - 1,200,200,200); $graphImage->setFontProperties(PCHARTFONTS_DIR . $this->xaxisfont, $this->xaxisfontsize); /* Define the chart area */ $graphImage->setGraphArea($this->marginleft_actual, $this->margintop_actual, $this->width_pdf_actual - $this->marginright_actual, $this->height_pdf_actual - $this->marginbottom_actual); $graphImage->drawFilledRoundedRectangle(3, 3, $this->width_pdf_actual - 3, $this->height_pdf_actual - 3, 5, 240, 240, 240); $graphImage->drawRoundedRectangle(1, 1, $this->width_pdf_actual - 1, $this->height_pdf_actual - 1, 5, 230, 230, 230); // Before plotting a series ensure they are all not drawable. /// Plot the chart data $stackeddrawn = false; $linedrawn = false; $scatterdrawn = false; $piedrawn = false; $stackedexists = false; $overlayexists = false; $barexists = false; foreach ($this->plot as $k => $v) { if ($v["type"] == "OVERLAYBAR") { $overlayexists = true; } if ($v["type"] == "STACKEDBAR") { $stackedexists = true; } if ($v["type"] == "STACKEDBAR" || $v["type"] == "BAR") { $barexists = true; } // Set plot colors if ($v["linecolor"]) { $graphImage->Palette[$k] = htmltorgb_pchart($v["linecolor"]); } $url .= "&plotlinecolor{$k}=" . $v["linecolor"]; } $scale_drawing_mode = SCALE_NORMAL; $scale_drawing_mode = SCALE_START0; // For stacked charts fix up the Max and Min values; if ($stackedexists) { $scale_drawing_mode = SCALE_ADDALL; $scaleMin = "Unknown"; $scaleMax = 0; $min = false; $max = false; foreach ($plot as $k => $v) { if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") { $series = $v["name"] . $k; minmaxValueOfSeries($v["data"], $min, $max); if ($scaleMin == "Unknown" || $min < $scaleMin) { $scaleMin = $min; } $scaleMax = $scaleMax + $max; } } if ($scaleMin > 0) { $scaleMin = 0; } $range = $scaleMax - $scaleMin; // Make scales based on 5% of the range of values $scaleMax = round($range * 0.05 + $scaleMax); if ($scaleMin < 0) { $scaleMin = $scaleMin - round($range * 0.05); } $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax)); } else { if ($barexists || $overlayexists) { $scaleMin = "Unknown"; $scaleMax = 0; $min = false; $max = false; foreach ($this->plot as $k => $v) { if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") { $series = $v["name"] . $k; minmaxValueOfSeries($v["data"], $min, $max); if ($scaleMin == "Unknown" || $min < $scaleMin) { $scaleMin = $min; } if ($scaleMax == "Unknown" || $max > $scaleMax) { $scaleMax = $max; } } } if ($scaleMin > 0) { $scaleMin = 0; } $range = $scaleMax - $scaleMin; // Make scales based on 5% of the range of values $scaleMax = round($range * 0.05 + $scaleMax); if ($scaleMin < 0) { $scaleMin = $scaleMin - round($range * 0.05); } $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax)); } } //echo "<PRE>"; //var_dump($graphData->GetDataDescription()); //die; // Find out if a scale is required, will be except for pie charts $scalerequired = false; foreach ($this->plot as $k => $v) { switch ($v["type"]) { case "BAR": case "STACKEDBAR": case "OVERLAYBAR": case "LINE": $scalerequired = "NORMAL"; break; case "SCATTER": $scalerequired = "SCATTER"; break; } } $graphImage->setFontProperties(PCHARTFONTS_DIR . $this->xtitlefont, $this->xtitlefontsize); if ($scalerequired) { $graphImage->setGraphArea($this->marginleft_actual, $this->margintop_actual, $this->width_pdf_actual - $this->marginright, $this->height_pdf_actual - $this->marginbottom_actual); $graphImage->drawGraphAreaGradient(240, 240, 240, -20); // Automatic generation of x tick interval based on number of ticks if ($this->xticklabelinterval_actual == "AUTO") { $labct = count($this->plot[0]["data"]); $this->xticklabelinterval_actual = floor($labct / 35) + 1; } if ($scalerequired == "NORMAL") { $graphImage->drawScale($graphData->GetData(), $graphData->GetDataDescription(), $scale_drawing_mode, 0, 0, 0, TRUE, 40, FALSE, TRUE, $this->xticklabelinterval_actual, FALSE); } $graphImage->drawGrid(2, TRUE, 230, 230, 230, 45); } else { $this->marginright = 5; $this->marginbottom = 5; $this->marginleft = 5; $this->marginright_actual = 5; $this->marginbottom_actual = 5; $this->marginleft_actual = 5; //$this->margintop_actual = 5; $graphImage->setGraphArea($this->marginleft, $this->margintop_actual, $this->width_pdf_actual - $this->marginright, $this->height_pdf_actual - $this->marginbottom); $graphImage->drawGraphAreaGradient(240, 240, 240, -10); } // If there's a Pie chart we want to draw different legends $piechart = false; foreach ($this->plot as $k => $v) { disableAllSeries($this->plot, $graphData); $series = $v["name"] . $k; setSerieDrawable($this->plot, $graphData, $series, TRUE); switch ($v["type"]) { case "PIE": $piedrawn = true; $piechart = true; $graphImage->drawFilledCircle($this->width_pdf_actual / 2 + 2, $this->margintop_actual + 2 + ($this->height_pdf_actual - $this->margintop_actual - $this->marginbottom_actual) / 2, ($this->height_pdf_actual - $this->marginbottom_actual - $this->margintop_actual - 20) * 0.45 + 1, 200, 200, 200); $graphImage->drawBasicPieGraph($graphData->GetData(), $graphData->GetDataDescription(), $this->width_pdf_actual / 2, $this->margintop_actual + ($this->height_pdf_actual - $this->margintop_actual - $this->marginbottom_actual) / 2, ($this->height_pdf_actual - $this->marginbottom_actual - $this->margintop_actual - 20) * 0.45, PIE_PERCENTAGE_LABEL, 255, 255, 218); break; case "PIE3D": $piedrawn = true; $piechart = true; $graphImage->drawPieGraph($graphData->GetData(), $graphData->GetDataDescription(), $this->width_pdf_actual / 2, $this->margintop_actual + ($this->height_pdf_actual - $this->margintop_actual - $this->marginbottom_actual) / 2, ($this->height_pdf_actual - $this->marginbottom_actual - $this->margintop_actual - 20) * 0.5, PIE_PERCENTAGE_LABEL, true, 60, 20, 0, 0); break; case "OVERLAYBAR": case "STACKEDBAR": case "BAR": if ($stackeddrawn) { break; } if ($barexists || $overlayexists) { foreach ($this->plot as $k1 => $v1) { if ($v1["type"] == "BAR" || $v1["type"] == "STACKEDBAR" || $v1["type"] == "OVERLAYBAR") { setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE); } } } $stackeddrawn = true; if ($stackedexists) { $graphImage->drawStackedBarGraph($graphData->GetData(), $graphData->GetDataDescription(), 90); } else { if ($overlayexists) { $graphImage->drawOverlayBarGraph($graphData->GetData(), $graphData->GetDataDescription(), 90); } else { $graphImage->drawBarGraph($graphData->GetData(), $graphData->GetDataDescription()); } } break; case "SCATTER": if ($scatterdrawn) { break; } $scatterdrawn = true; $series1 = false; $series2 = false; $graphImage->reportWarnings("GD"); $ct = 0; foreach ($this->plot as $k1 => $v1) { if ($v1["type"] == "SCATTER") { if ($ct == 0) { $series1 = $v1["name"] . $k1; } if ($ct == 1) { $series2 = $v1["name"] . $k1; } $ct++; setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE); } } if (count($v["data"]) == 1) { $v["data"][] = 0; } $graphImage->drawXYScale($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2, 0, 0, 0); //$graphImage->drawXYGraph($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2); $graphImage->drawXYPlotGraph($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2); $graphImage->writeValues($graphData->GetData(), $graphData->GetDataDescription(), $series2); break; case "LINE": default: if ($linedrawn) { break; } $linedrawn = true; foreach ($this->plot as $k1 => $v1) { if ($v1["type"] == "LINE") { setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE); } } if (count($v["data"]) == 1) { $v["data"][] = 0; } $graphImage->LineWidth = 1; $graphImage->drawLineGraph($graphData->GetData(), $graphData->GetDataDescription()); $graphImage->drawPlotGraph($graphData->GetData(), $graphData->GetDataDescription()); $graphImage->LineWidth = 1; break; } } foreach ($this->plot as $k1 => $v1) { setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE); } // Draw Legend if legend value has been set $drawlegend = false; foreach ($this->plot as $k => $v) { if (isset($v["legend"]) && $v["legend"]) { // Temporarily Dont draw legend for Pie //if ( $piechart ) //$graphImage->drawPieLegend($this->width_pdf_actual - 180,30,$graphData->GetData(), $graphData->GetDataDescription(), 250, 250, 250); if (!$piechart) { $graphImage->drawLegend($this->width_pdf_actual - 120, 30, $graphData->GetDataDescription(), 254, 254, 254, 0, 0, 0); } break; } } $graphImage->setFontProperties(PCHARTFONTS_DIR . $this->xtitlefont, $this->titlefontsize); $graphImage->drawTitle(0, 24, $this->title_actual, 50, 50, 50, $this->width_pdf_actual); //$graphImage->setShadow(TRUE,array("X"=>0,"Y"=>0,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); //$graphImage->Render("example.png"); //$graphImage->Stroke(); $graphImage->render($outputfile); return true; }
public function pchartAction() { // $this->_helper->layout->disableLayout(); $this->_helper->layout->setLayout("layout_admin"); include "pData.class"; include "pChart.class"; $this->view->showArray = $this->testdemoAction(); $showdate = array(); $showreport = array(); foreach ($this->view->showArray as $show) { array_push($showdate, substr($show['date'], strlen($show['date']) - 4, 4)); array_push($showreport, $show['count']); } // Dataset definition $DataSet = new pData(); $DataSet->AddPoint(array_slice($showreport, 0, 26), "Serie1"); $DataSet->AddPoint(array_slice($showdate, 0, 26), "Serie2"); $DataSet->AddSerie("Serie1"); $DataSet->SetAbsciseLabelSerie("Serie2"); $DataSet->SetSerieName("Reports", "Serie1"); $DataSet->SetYAxisName('Report Count'); $DataSet->SetXAxisName('Date'); // Initialise the graph $Test = new pChart(900, 250); $Test->setFontProperties("xihei.ttf", 8); $Test->setGraphArea(50, 30, 780, 200); $Test->drawFilledRoundedRectangle(7, 7, 793, 248, 5, 255, 255, 255); $Test->drawRoundedRectangle(5, 5, 795, 249, 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("xihei.ttf", 6); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the bar graph $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE); // Finish the graph $Test->setFontProperties("xihei.ttf", 8); $Test->drawLegend(596, 50, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties("xihei.ttf", 10); $Test->drawTitle(200, 22, "Reports by Day in Jue.", 50, 50, 50, 585); $Test->Render("Naked1.png"); //===================================================================================== // Dataset definition $DataSet2 = new pData(); $DataSet2->AddPoint(array(38, 22, 606), "Serie1"); $DataSet2->AddPoint(array("Male", "Female", "Unkown"), "Serie2"); $DataSet2->AddAllSeries(); $DataSet2->SetAbsciseLabelSerie("Serie2"); // Initialise the graph $Test2 = new pChart(300, 200); $Test2->loadColorPalette("softtones.txt"); $Test2->drawFilledRoundedRectangle(7, 7, 293, 193, 5, 255, 255, 255); $Test2->drawRoundedRectangle(5, 5, 295, 195, 5, 230, 230, 230); // This will draw a shadow under the pie chart $Test2->drawFilledCircle(122, 102, 70, 200, 200, 200); // Draw the pie chart $Test2->setFontProperties("tahoma.ttf", 8); $Test2->drawBasicPieGraph($DataSet2->GetData(), $DataSet2->GetDataDescription(), 120, 100, 70, PIE_PERCENTAGE, 255, 255, 218); $Test2->drawPieLegend(230, 15, $DataSet2->GetData(), $DataSet2->GetDataDescription(), 250, 250, 250); $Test2->Render("Naked2.png"); //===================================================================================== // select province $db = Zend_Registry::get('db'); $selectprovince = $db->select(); $selectprovince->from('consumer', array("province", "count(*) as count"))->where("pest is null")->group("consumer.province")->order("count desc"); $provinceArray = $db->fetchAll($selectprovince); $this->view->showprovince = ''; $this->view->showprovincecount = ''; $showprovince = array(); $showprovincecount = array(); foreach ($provinceArray as $province) { if ($province['province'] == null || $province['province'] == '') { array_push($showprovince, 'Unkown'); } else { array_push($showprovince, $province['province']); } array_push($showprovincecount, $province['count']); } // Dataset definition $DataSet3 = new pData(); $DataSet3->AddPoint(array_slice($showprovincecount, 0, 20), "Serie1"); $DataSet3->AddPoint(array_slice($showprovince, 0, 20), "Serie2"); $DataSet3->AddSerie("Serie1"); $DataSet3->SetAbsciseLabelSerie("Serie2"); $DataSet3->SetSerieName("Spark Count", "Serie1"); $DataSet3->SetYAxisName('Spark Count'); $DataSet3->SetXAxisName('Province'); Zend_Debug::dump($DataSet3->GetDataDescription()); // Initialise the graph $Test3 = new pChart(900, 250); $Test3->setFontProperties("xihei.ttf", 8); $Test3->setGraphArea(50, 30, 780, 200); $Test3->drawFilledRoundedRectangle(7, 7, 793, 248, 5, 255, 255, 255); $Test3->drawRoundedRectangle(5, 5, 795, 249, 5, 230, 230, 230); $Test3->drawGraphArea(255, 255, 255, TRUE); $Test3->drawScale($DataSet3->GetData(), $DataSet3->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE); $Test3->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the 0 line $Test3->setFontProperties("xihei.ttf", 6); $Test3->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the bar graph $Test3->drawBarGraph($DataSet3->GetData(), $DataSet3->GetDataDescription(), TRUE); // Finish the graph $Test3->setFontProperties("xihei.ttf", 8); $Test3->drawLegend(596, 50, $DataSet3->GetDataDescription(), 255, 255, 255); $Test3->setFontProperties("xihei.ttf", 10); $Test3->drawTitle(200, 22, "Reports by Day in Jue.", 50, 50, 50, 585); $Test3->Render("Naked3.png"); }
$DataSet->AddPoint($array_to_display, "Serie1"); $DataSet->AddPoint(array("Jan", "Fev", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Sept.", "Oct.", "Nov.", "Dec."), "Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("Serie2"); $DataSet->SetSerieName("{$machine_to_display}", "Serie1"); $DataSet->SetXAxisName("Mois"); $DataSet->SetYAxisName("Downtime"); $DataSet->SetYAxisUnit(" h"); // Initialise the graph $Test = new pChart(500, 250); $Test->setFontProperties("../../pChart/Fonts/tahoma.ttf", 10); $Test->setGraphArea(70, 30, 480, 200); $Test->drawFilledRoundedRectangle(7, 7, 493, 243, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 495, 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("../../pChart/Fonts/tahoma.ttf", 10); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the line graph $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255); $Test->writeValues($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie1"); // Finish the graph $Test->setFontProperties("../../pChart/Fonts/tahoma.ttf", 8); //$Test->drawLegend(75,35,$DataSet->GetDataDescription(),255,255,255); $Test->setFontProperties("../../pChart/Fonts/tahoma.ttf", 10); $Test->drawTitle(60, 22, "Downtime par mois", 50, 50, 50, 585); //$Test->Render("example1.png"); $Test->stroke();
/** * * Generate a chart for a question * @param int $iQuestionID ID of the question * @param int $iSurveyID ID of the survey * @param mixed $type Type of the chart to be created - null produces bar chart, any other value produces pie chart * @param array $lbl An array containing the labels for the chart items * @param mixed $gdata An array containing the percentages for the chart items * @param mixed $grawdata An array containing the raw count for the chart items * @param mixed $cache An object containing [Hashkey] and [CacheFolder] * @param string $sQuestionType The question type * @return Name */ function createChart($iQuestionID, $iSurveyID, $type = null, $lbl, $gdata, $grawdata, $cache, $oLanguage, $sQuestionType) { /* This is a lazy solution to bug #6389. A better solution would be to find out how the "T" gets passed to this function from the statistics.js file in the first place! */ if (substr($iSurveyID, 0, 1) == "T") { $iSurveyID = substr($iSurveyID, 1); } static $bErrorGenerate = false; if ($bErrorGenerate) { return false; } $rootdir = Yii::app()->getConfig("rootdir"); $homedir = Yii::app()->getConfig("homedir"); $homeurl = Yii::app()->getConfig("homeurl"); $admintheme = Yii::app()->getConfig("admintheme"); $scriptname = Yii::app()->getConfig("scriptname"); $chartfontfile = Yii::app()->getConfig("chartfontfile"); $chartfontsize = Yii::app()->getConfig("chartfontsize"); $alternatechartfontfile = Yii::app()->getConfig("alternatechartfontfile"); $language = $oLanguage->langcode; $cachefilename = ""; /* Set the fonts for the chart */ if ($chartfontfile == 'auto') { // Tested with ar,be,el,fa,hu,he,is,lt,mt,sr, and en (english) // Not working for hi, si, zh, th, ko, ja : see $config['alternatechartfontfile'] to add some specific language font $chartfontfile = 'DejaVuSans.ttf'; if (array_key_exists($language, $alternatechartfontfile)) { $neededfontfile = $alternatechartfontfile[$language]; if (is_file($rootdir . "/fonts/" . $neededfontfile)) { $chartfontfile = $neededfontfile; } else { Yii::app()->setFlashMessage(sprintf(gT('The fonts file %s was not found in <limesurvey root folder>/fonts directory. Please, see the txt file for your language in fonts directory to generate the charts.'), $neededfontfile), 'error'); $bErrorGenerate = true; // Don't do a graph again. return false; } } } if (count($lbl) > 72) { $DataSet = array(1 => array(1 => 1)); if ($cache->IsInCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet) && Yii::app()->getConfig('debug') < 2) { $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet)); } else { $graph = new pChart(690, 200); $graph->loadColorPalette($homedir . DIRECTORY_SEPARATOR . 'styles' . DIRECTORY_SEPARATOR . $admintheme . DIRECTORY_SEPARATOR . 'limesurvey.pal'); $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize); $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize); $graph->drawTitle(0, 0, gT('Sorry, but this question has too many answer options to be shown properly in a graph.', 'unescaped'), 30, 30, 30, 690, 200); $cache->WriteToCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet, $graph); $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet)); unset($graph); } return $cachefilename; } if (array_sum($gdata) == 0) { $DataSet = array(1 => array(1 => 1)); if ($cache->IsInCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet) && Yii::app()->getConfig('debug') < 2) { $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet)); } else { $graph = new pChart(690, 200); $graph->loadColorPalette($homedir . DIRECTORY_SEPARATOR . 'styles' . DIRECTORY_SEPARATOR . $admintheme . DIRECTORY_SEPARATOR . 'limesurvey.pal'); $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize); $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize); $graph->drawTitle(0, 0, gT('Sorry, but this question has no responses yet so a graph cannot be shown.', 'unescaped'), 30, 30, 30, 690, 200); $cache->WriteToCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet, $graph); $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet)); unset($graph); } return $cachefilename; } if (array_sum($gdata) > 0) { $graph = ""; $p1 = ""; $i = 0; foreach ($gdata as $data) { if ($data != 0) { $i++; } } /* Totatllines is the number of entries to show in the key and we need to reduce the font and increase the size of the chart if there are lots of them (ie more than 15) */ $totallines = $i; if ($totallines > 15) { $gheight = 320 + 6.7 * ($totallines - 15); $fontsize = 7; $legendtop = 0.01; $setcentrey = 0.5 / ($gheight / 320); } else { $gheight = 320; $fontsize = 8; $legendtop = 0.07000000000000001; $setcentrey = 0.5; } if (!$type) { $DataSet = new pData(); $counter = 0; $maxyvalue = 0; foreach ($grawdata as $datapoint) { $DataSet->AddPoint(array($datapoint), "Serie{$counter}"); $DataSet->AddSerie("Serie{$counter}"); $counter++; if ($datapoint > $maxyvalue) { $maxyvalue = $datapoint; } } if ($maxyvalue < 10) { ++$maxyvalue; } if ($language == 'ar') { if (!class_exists('I18N_Arabic_Glyphs', false)) { $Arabic = new I18N_Arabic('Glyphs'); } else { $Arabic = new I18N_Arabic_Glyphs(); } foreach ($lbl as $kkey => $kval) { if (preg_match("^[A-Za-z]^", $kkey)) { //auto detect if english $lblout[] = $kkey . ' (' . $kval . ')'; } else { $lblout[] = $Arabic->utf8Glyphs($kkey . ' )' . $kval . '('); } } } elseif (getLanguageRTL($language)) { foreach ($lbl as $kkey => $kval) { $lblout[] = UTF8Strrev($kkey . ' )' . $kval . '('); } } else { foreach ($lbl as $kkey => $kval) { $lblout[] = $kkey . ' (' . $kval . ')'; } } $counter = 0; foreach ($lblout as $sLabelName) { $DataSet->SetSerieName(html_entity_decode($sLabelName, null, 'UTF-8'), "Serie{$counter}"); $counter++; } if ($cache->IsInCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData()) && Yii::app()->getConfig('debug') < 2) { $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData())); } else { $graph = new pChart(1, 1); $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize); $legendsize = $graph->getLegendBoxSize($DataSet->GetDataDescription()); if ($legendsize[1] < 320) { $gheight = 420; } else { $gheight = $legendsize[1] + 100; } $graph = new pChart(690 + $legendsize[0], $gheight); $graph->drawFilledRectangle(0, 0, 690 + $legendsize[0], $gheight, 254, 254, 254, false); $graph->loadColorPalette($homedir . DIRECTORY_SEPARATOR . 'styles' . DIRECTORY_SEPARATOR . $admintheme . DIRECTORY_SEPARATOR . 'limesurvey.pal'); $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize); $graph->setGraphArea(50, 30, 500, $gheight - 60); $graph->drawFilledRoundedRectangle(7, 7, 523 + $legendsize[0], $gheight - 7, 5, 254, 255, 254); $graph->drawRoundedRectangle(5, 5, 525 + $legendsize[0], $gheight - 5, 5, 230, 230, 230); $graph->drawGraphArea(254, 254, 254, TRUE); $graph->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 90, 0, TRUE, 5, false); $graph->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the 0 line $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize); $graph->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the bar graph $graph->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), FALSE); //$Test->setLabel($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie4","1","Important point!"); // Finish the graph $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize); $graph->drawLegend(510, 30, $DataSet->GetDataDescription(), 250, 250, 250); $cache->WriteToCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData(), $graph); $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData())); unset($graph); } } else { // this block is to remove the items with value == 0 // and an inelegant way to remove comments from List with Comments questions $i = 0; $j = 0; $labelTmp = array(); while (isset($gdata[$i])) { $aHelperArray = array_keys($lbl); if ($gdata[$i] == 0 || $sQuestionType == "O" && substr($aHelperArray[$i], 0, strlen($oLanguage->gT("Comments"))) == $oLanguage->gT("Comments")) { array_splice($gdata, $i, 1); } else { $i++; $labelTmp = $labelTmp + array_slice($lbl, $j, 1, true); // Preserve numeric keys for the labels! } $j++; } $lbl = $labelTmp; if ($language == 'ar') { if (!class_exists('I18N_Arabic_Glyphs', false)) { $Arabic = new I18N_Arabic('Glyphs'); } else { $Arabic = new I18N_Arabic_Glyphs(); } foreach ($lbl as $kkey => $kval) { if (preg_match("^[A-Za-z]^", $kkey)) { //auto detect if english $lblout[] = $kkey . ' (' . $kval . ')'; } else { $lblout[] = $Arabic->utf8Glyphs($kkey . ' )' . $kval . '('); } } } elseif (getLanguageRTL($language)) { foreach ($lbl as $kkey => $kval) { $lblout[] = UTF8Strrev(html_entity_decode($kkey, null, 'UTF-8') . ' )' . $kval . '('); } } else { foreach ($lbl as $kkey => $kval) { $lblout[] = html_entity_decode($kkey, null, 'UTF-8') . ' (' . $kval . ')'; } } //create new 3D pie chart $DataSet = new pData(); $DataSet->AddPoint($gdata, "Serie1"); $DataSet->AddPoint($lblout, "Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("Serie2"); if ($cache->IsInCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData()) && Yii::app()->getConfig('debug') < 2) { $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData())); } else { $gheight = ceil($gheight); $graph = new pChart(690, $gheight); $graph->drawFilledRectangle(0, 0, 690, $gheight, 254, 254, 254, false); $graph->loadColorPalette($homedir . '/styles/' . $admintheme . '/limesurvey.pal'); $graph->drawFilledRoundedRectangle(7, 7, 687, $gheight - 3, 5, 254, 255, 254); $graph->drawRoundedRectangle(5, 5, 689, $gheight - 1, 5, 230, 230, 230); // Draw the pie chart $graph->setFontProperties($rootdir . "/fonts/" . $chartfontfile, $chartfontsize); $graph->drawPieGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 225, round($gheight / 2), 170, PIE_PERCENTAGE, TRUE, 50, 20, 5); $graph->setFontProperties($rootdir . "/fonts/" . $chartfontfile, $chartfontsize); $graph->drawPieLegend(430, 12, $DataSet->GetData(), $DataSet->GetDataDescription(), 250, 250, 250); $cache->WriteToCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData(), $graph); $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData())); unset($graph); } } //end else -> pie charts } return $cachefilename; }
// Draw Labels $Test->setFontProperties("../charts/Fonts/tahoma.ttf", 8); if (!empty($ally)) { foreach ($ally as $k => $v) { if ($v != 0) { $_alliance = $redis->HGETALL("alliance:{$v}:data"); $Test->setLabel($DataSet->GetData(), $DataSet->GetDataDescription(), "rank", $k, "Ally: {$_alliance['name']}", 221, 230, 174); } else { $Test->setLabel($DataSet->GetData(), $DataSet->GetDataDescription(), "rank", $k, "keine Alliance", 221, 230, 174); } } } // Finish the graph $Test->drawLegend(75, 35, $DataSet->GetDataDescription(), 236, 238, 240, 52, 58, 82); $Test->setFontProperties("../charts/Fonts/tahoma.ttf", 10); $Test->drawTitle(60, 22, $user['name'] . (!empty($alliance['name']) ? ' [' . $alliance['name'] . ']' : '') . ' - ' . $scale_hours . 'h' . ' Performance: ' . $performance . '%' . $inactive_text, 50, 50, 50, 585); // Render the graph $Cache->WriteToCache(md5($user['name']), $DataSet->GetData(), $Test); $Test->Render($FileName); } } $reload_uri = str_replace('&c=0', '', $_SERVER['REQUEST_URI']); header("refresh:600;url={$reload_uri}"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-type: text/html; charset=utf-8"); ?> <html> <head> <title><?php
/** * Generates a big graph with the number of best results * @param array */ static function generate_exercise_result_graph($attempts) { require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php'; require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php'; require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php'; $exercise_title = strip_tags($attempts['title']); $attempts = $attempts['data']; $my_exercise_result_array = $exercise_result = array(); if (empty($attempts)) { return null; } foreach ($attempts as $attempt) { if (api_get_user_id() == $attempt['exe_user_id']) { if ($attempt['exe_weighting'] != 0 ) { $my_exercise_result_array[]= $attempt['exe_result']/$attempt['exe_weighting']; } } else { if ($attempt['exe_weighting'] != 0 ) { $exercise_result[]= $attempt['exe_result']/$attempt['exe_weighting']; } } } //Getting best result rsort($my_exercise_result_array); $my_exercise_result = 0; if (isset($my_exercise_result_array[0])) { $my_exercise_result = $my_exercise_result_array[0] *100; } $max = 100; $pieces = 5 ; $part = round($max / $pieces); $x_axis = array(); $final_array = array(); $my_final_array = array(); for ($i=1; $i <=$pieces; $i++) { $sum = 1; if ($i == 1) { $sum = 0; } $min = ($i-1)*$part + $sum; $max = ($i)*$part; $x_axis[]= $min." - ".$max; $count = 0; foreach($exercise_result as $result) { $percentage = $result*100; //echo $percentage.' - '.$min.' - '.$max."<br />"; if ($percentage >= $min && $percentage <= $max) { //echo ' is > '; $count++; } } //echo '<br />'; $final_array[]= $count; if ($my_exercise_result >= $min && $my_exercise_result <= $max) { $my_final_array[] = 1; } else { $my_final_array[] = 0; } } //Fix to remove the data of the user with my data for($i = 0; $i<=count($my_final_array); $i++) { if (!empty($my_final_array[$i])) { $my_final_array[$i] = $final_array[$i] + 1; //Add my result $final_array[$i] = 0; } } $cache = new pCache(); // Dataset definition $data_set = new pData(); $data_set->AddPoint($final_array,"Serie1"); $data_set->AddPoint($my_final_array,"Serie2"); $data_set->AddPoint($x_axis,"Serie3"); $data_set->AddAllSeries(); $data_set->SetAbsciseLabelSerie('Serie3'); $data_set->SetSerieName(get_lang('Score'),"Serie1"); $data_set->SetSerieName(get_lang('MyResults'),"Serie2"); $data_set->SetXAxisName(get_lang("Score")); // Initialise the graph $main_width = 500; $main_height = 250; $main_graph = new pChart($main_width,$main_height); $main_graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8); $main_graph->setGraphArea(50,30, $main_width -20,$main_height -50); $main_graph->drawFilledRoundedRectangle(10,10, $main_width- 10,$main_height -10,5,240,240,240); $main_graph->drawRoundedRectangle(7,7,$main_width - 7,$main_height - 7,5,230,230,230); $main_graph->drawGraphArea(255,255,255,TRUE); //SCALE_NORMAL, SCALE_START0, SCALE_ADDALLSTART0 $main_graph->drawScale($data_set->GetData(),$data_set->GetDataDescription(),SCALE_ADDALLSTART0, 150,150,150,TRUE,0,1,TRUE); $main_graph->drawGrid(4,TRUE,230,230,230,50); // Draw the 0 line $main_graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',6); // $main_graph->drawTreshold(0,143,55,72,TRUE,TRUE); // Draw the bar graph $data_set->RemoveSerie("Serie3"); //$main_graph->drawBarGraph($data_set->GetData(),$data_set->GetDataDescription(),TRUE); //$main_graph->drawStackedBarGraph($data_set->GetData(),$data_set->GetDataDescription(),TRUE); $main_graph->drawOverlayBarGraph($data_set->GetData(),$data_set->GetDataDescription(), 100); // Finish the graph $main_graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8); $main_graph->drawLegend($main_width - 120,$main_height -100,$data_set->GetDataDescription(),255,255,255); $main_graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8); $main_graph->drawTitle(180,22,$exercise_title,50,50,50); $graph_id = 'exercise_result_graph'.Security::remove_XSS($_GET['course']).'-'.intval($_GET['session_id']).'-'.api_get_user_id(); if ($cache->IsInCache($graph_id, $data_set->GetData())) { //if (0) { //if we already created the img //echo 'in cache'; $img_file = $cache->GetHash($graph_id,$data_set->GetData()); } else { $cache->WriteToCache($graph_id, $data_set->GetData(), $main_graph); ob_start(); $main_graph->Stroke(); ob_end_clean(); $img_file = $cache->GetHash($graph_id, $data_set->GetData()); } $html = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">'; return $html; }
// Dataset definition $DataSet = new pData(); $DataSet->ImportFromCSV("Sample/bulkdata.csv", ",", array(1, 2, 3), FALSE, 0); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie(); $DataSet->SetSerieName("January", "Serie1"); $DataSet->SetSerieName("February", "Serie2"); $DataSet->SetSerieName("March", "Serie3"); $DataSet->SetYAxisName("Average age"); $DataSet->SetYAxisUnit("µs"); // Initialise the graph $Test = new pChart(700, 230); $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(70, 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 line graph $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255); // Finish the graph $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->drawLegend(75, 35, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties("Fonts/tahoma.ttf", 10); $Test->drawTitle(60, 22, "example 1", 50, 50, 50, 585); $Test->Render("example1.png");
$Point1[] = $myrow['value']; $Point2[] = $myrow['stockid']; } // Dataset definition $DataSet = new pData(); $DataSet->AddPoint($Point1, "Serie1"); $DataSet->AddPoint($Point2, "Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("Serie2"); // 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("includes/pchart/Fonts/tahoma.ttf", 8); $Test->AntialiasQuality = 0; $Test->drawPieGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 180, 130, 110, PIE_PERCENTAGE_LABEL, FALSE, 50, 20, 5); $Test->drawPieLegend(330, 15, $DataSet->GetData(), $DataSet->GetDataDescription(), 250, 250, 250); // Write the title $Test->setFontProperties("includes/pchart/Fonts/MankSans.ttf", 10); $Test->drawTitle(10, 20, "Sales per month", 100, 100, 100); $Test->Render("example10.png"); echo '<tr><th colspan="5"><font color="navy" size="2">'; echo _('Income for the previous week'); echo '</font></th></tr>'; echo '<td>'; echo '<img src=example10.png />'; echo '</td></tr></table>'; echo '</td></table>'; include 'includes/footer.inc';
function display_graph_by_resource() { require_once api_get_path(LIBRARY_PATH) . 'pchart/pData.class.php'; require_once api_get_path(LIBRARY_PATH) . 'pchart/pChart.class.php'; require_once api_get_path(LIBRARY_PATH) . 'pchart/pCache.class.php'; $header_name = $this->datagen->get_header_names(); $total_users = $this->datagen->get_total_users_count(); $img_file = ''; if ($this->datagen->get_total_items_count() > 0 && $total_users > 0) { //Removing first name array_shift($header_name); //Removing last name array_shift($header_name); $displayscore = ScoreDisplay::instance(); $customdisplays = $displayscore->get_custom_score_display_settings(); if (is_array($customdisplays) && count($customdisplays)) { $user_results = $this->datagen->get_data_to_graph2(); $pre_result = $new_result = array(); $DataSet = new pData(); //filling the Dataset foreach ($user_results as $result) { //print_r($result); for ($i = 0; $i < count($header_name); $i++) { $pre_result[$i + 3][] = $result[$i + 1]; } } $i = 0; $show_draw = false; $resource_list = array(); $pre_result2 = array(); foreach ($pre_result as $key => $res_array) { rsort($res_array); $pre_result2[] = $res_array; } //@todo when a display custom does not exist the order of the color does not match //filling all the answer that are not responded with 0 rsort($customdisplays); if ($total_users > 0) { foreach ($pre_result2 as $key => $res_array) { $key_list = array(); foreach ($res_array as $user_result) { $resource_list[$key][$user_result[1]] += 1; $key_list[] = $user_result[1]; } foreach ($customdisplays as $display) { if (!in_array($display['display'], $key_list)) { $resource_list[$key][$display['display']] = 0; } } $i++; } } //fixing $resource_list $max = 0; $new_list = array(); foreach ($resource_list as $key => $value) { $new_value = array(); foreach ($customdisplays as $item) { if ($value[$item['display']] > $max) { $max = $value[$item['display']]; } $new_value[$item['display']] = strip_tags($value[$item['display']]); } $new_list[] = $new_value; } $resource_list = $new_list; $i = 1; $j = 0; foreach ($resource_list as $key => $resource) { $new_resource_list = $new_resource_list_name = array(); $DataSet = new pData(); // Reverse array, otherwise we get highest values first $resource = array_reverse($resource, true); foreach ($resource as $name => $cant) { $DataSet->AddPoint($cant, "Serie" . $j); $DataSet->SetSerieName(strip_tags($name), "Serie" . $j); $j++; } //print_r($pre_result); print_r($header_name); // Dataset definition $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie(''); $DataSet->SetXAxisName(get_lang('GradebookSkillsRanking')); $DataSet->SetYAxisName(get_lang('Students')); $show_draw = true; // Cache definition $Cache = new pCache(); // the graph id $gradebook_id = intval($_GET['selectcat']); $graph_id = api_get_user_id() . 'ByResource' . $gradebook_id . api_get_course_id() . api_get_session_id(); if ($show_draw) { //if ($Cache->IsInCache($graph_id, $DataSet->GetData())) { if (0) { //if we already created the img we get the img file id //echo 'in cache'; $img_file = $Cache->GetHash($graph_id, $DataSet->GetData()); } else { // if the image does not exist in the archive/ folder // Initialise the graph $chart_size_w = 480; $chart_size_h = 250; $Test = new pChart($chart_size_w, $chart_size_h); // Adding the color schemma $Test->loadColorPalette(api_get_path(LIBRARY_PATH) . "pchart/palette/pastel.txt"); // set font of the axes $Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 8); $area_graph_w = $chart_size_w - 130; $Test->setGraphArea(50, 30, $area_graph_w, $chart_size_h - 50); $Test->drawFilledRoundedRectangle(5, 5, $chart_size_w - 1, $chart_size_h - 20, 5, 240, 240, 240); //$Test->drawRoundedRectangle(5,5,790,330,5,230,230,230); //background color area & stripe or not $Test->drawGraphArea(255, 255, 255, TRUE); //Setting max height by default see #3296 if (!empty($max)) { $Test->setFixedScale(0, $max); } $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALLSTART0, 150, 150, 150, TRUE, 0, 0, FALSE); //background grid $Test->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the 0 line //$Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",6); //$Test->drawTreshold(0,143,55,72,TRUE,TRUE); // Draw the bar graph $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE); //Set legend properties: width, height and text color and font $Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 9); $Test->drawLegend($area_graph_w + 10, 50, $DataSet->GetDataDescription(), 255, 255, 255); //Set title properties $Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 10); $Test->drawTitle(50, 22, strip_tags($header_name[$i - 1]), 50, 50, 80, $chart_size_w - 50); //------------------ //echo 'not in cache'; $Cache->WriteToCache($graph_id, $DataSet->GetData(), $Test); //ob_start(); //$Test->Stroke(); //ob_end_clean(); $img_file = $Cache->GetHash($graph_id, $DataSet->GetData()); } echo '<img src="' . api_get_path(WEB_ARCHIVE_PATH) . $img_file . '" >'; if ($i % 2 == 0 && $i != 0) { echo '<br />'; } $i++; } } //end foreach } else { echo get_lang('ToViewGraphScoreRuleMustBeEnabled'); } // Pie charts /* $show_draw = false; $resource_list = array(); //print_r($pre_result_pie); if ($total_users>0) { foreach($pre_result_pie as $key=>$res_array) { //$resource_list foreach($res_array as $user_result) { $total+= $user_result / ($total_users*100); } echo $total; //echo $total = $res / ($total_users*100); echo '<br>'; //$DataSet->AddPoint($total,"Serie".$i); //$DataSet->SetSerieName($header_name[$i-1],"Serie".$i); } } //here-------------- foreach($resource_list as $key=>$resource) { $new_resource_list = $new_resource_list_name = array(); foreach($resource as $name=>$cant) { $new_resource_list[]=$cant; $new_resource_list_name[]=$name; } //Pie chart $DataSet = new pData; $DataSet->AddPoint($new_resource_list,"Serie1"); $DataSet->AddPoint($new_resource_list_name,"Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("Serie2"); $Test = new pChart(400,300); $Test->loadColorPalette(api_get_path(LIBRARY_PATH)."pchart/palette/soft_tones.txt"); // background //$Test->drawFilledRoundedRectangle(7,7,293,193,5,240,240,240); // border color $Test->drawRoundedRectangle(5,5,295,195,5,230,230,230); // This will draw a shadow under the pie chart //$Test->drawFilledCircle(122,102,70,200,200,200); //Draw the pie chart $Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",8); $Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE); $tmp_path = api_get_path(SYS_ARCHIVE_PATH); $Test->drawBasicPieGraph($DataSet->GetData(),$DataSet->GetDataDescription(),120,100,70,PIE_PERCENTAGE,255,255,218); $Test->drawPieLegend(230,15,$DataSet->GetData(),$DataSet->GetDataDescription(),250,250,250); $user_id = api_get_user_id(); $img_file_generated_name = $key.uniqid('').'gradebook.png'; $Test->Render($tmp_path.$img_file_generated_name); chmod($tmp_path.$img_file_generated_name, api_get_permissions_for_new_files()); if ($i % 2 == 0 && $i!= 0) { echo '<br>'; } echo '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file_generated_name.'">'; } */ } }
// Dataset $DataSet->AddPoints(array(1, 4, 3, 2, 3, 3, 2, 1, 0, 7, 4, 3, 2, 3, 3, 5, 1, 0, 7), "Serie1"); $DataSet->AddPoints(array(1, 4, 2, 6, 2, 3, 0, 1, 5, 1, 2, 4, 5, 2, 1, 0, 6, 4, 2), "Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbscissaLabelSeries(); $DataSet->SetSeriesName("January", "Serie1"); $DataSet->SetSeriesName("February", "Serie2"); // Cache definition $Cache = new pCache(); $Cache->GetFromCache("Example11", $DataSet->GetData()); // Initialise the graph $Chart->setFontProperties("../Fonts/tahoma.ttf", 8); $Chart->setGraphArea(50, 30, 585, 200); $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 cubic curve graph $Chart->drawCubicCurve($DataSet, 0.1, "Serie1"); $Chart->drawCubicCurve($DataSet, 0.1, "Serie2"); // Finish the graph $Chart->setFontProperties("../Fonts/tahoma.ttf", 8); $Chart->drawLegend(600, 30, $DataSet->GetDataDescription(), new Color(255)); $Chart->setFontProperties("../Fonts/tahoma.ttf", 10); $Chart->drawTitle(50, 22, "Example 1", new Color(50), 585); // Render the graph $Cache->WriteToCache("Example11", $DataSet->GetData(), $Chart); $Chart->Render("Example11.png"); header("Content-Type:image/png"); readfile("Example11.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");
$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, $res['treinador'], 50, 50, 50, 585); $Test->Render("example" . $res['id_treinador'] . ".png"); ?> <img src="example<?php echo $res['id_treinador']; ?> .png" alt="<?php echo $res['id_treinador']; ?> " width="670"/> <b>Média: </b> <?php echo number_format($questao, 2); ?> <br><br><b>Questões</b><br> <label style="color:#0000FF">Pergunta 1: O Treinamento foi eficiente?</label> <?php echo number_format($questao1, 2);