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 index() { $this->load->model('charge_model'); $revenue = $this->charge_model->GetRevenueByDay($this->user->Get('client_id')); $data = array(); if ($this->config->item('show_dashboard_chart') !== 'no' and !empty($revenue) and count($revenue) > 1) { $series = array(); foreach ($revenue as $day) { $series[] = $day['revenue']; $series2[] = date("M j", strtotime($day['day'])); } include APPPATH . 'libraries/pchart/pData.class'; include APPPATH . 'libraries/pchart/pChart.class'; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint($series, "Revenue"); $DataSet->AddPoint($series2, "Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("Serie2"); $DataSet->RemoveSerie("Serie2"); $DataSet->SetXAxisName('Date'); $DataSet->SetYAxisName('Revenue'); //$DataSet->SetXAxisFormat('date'); // Initialise the graph $Test = new pChart(1000, 260); $Test->setFontProperties(APPPATH . 'libraries/pchart/Arial.ttf', 10); $Test->setGraphArea(90, 30, 960, 200); $Test->drawGraphArea(252, 252, 252); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2); $Test->drawGrid(4, TRUE, 230, 230, 230, 255); // 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(APPPATH . 'libraries/pchart/Arial.ttf', 8); $Test->drawLegend(45, 35, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties(APPPATH . 'libraries/pchart/Arial.ttf', 10); //$Test->drawTitle(60,22,"Last 30 Days",50,50,50,585); $Test->Render(BASEPATH . '../writeable/rev_chart_' . $this->user->Get('client_id') . '.png'); } else { $data['no_chart'] = 'true'; } // get log $this->load->model('log_model'); $log = $this->log_model->GetClientLog($this->user->Get('client_id')); $data['log'] = $log; $this->load->view(branded_view('cp/dashboard'), $data); }
private function _getDataObj() { //Setup the pData - Object (pChart Framework at http://pchart.sourceforge.net/) to feed the graph $data = new pData(); $data->AddPoint($this->ordinateSerie, "ORDINATE"); $data->AddSerie("ORDINATE"); $data->SetYAxisName($this->ordinateName); $data->SetSerieName($this->metricTitle, "ORDINATE"); $data->AddPoint($this->abscissaSerie, "ABSCISSA"); $data->SetAbsciseLabelSerie("ABSCISSA"); $data->SetXAxisName($this->abscissaName); return $data; }
public function componentLineGraph() { $DataSet = new pData(); $maxvals = array(); foreach ($this->datasets as $ds_id => $dataset) { $DataSet->AddPoint($dataset['values'], "Serie" . $ds_id, array_keys($dataset['values'])); $maxvals[] = max($dataset['values']); if (isset($dataset['burndown'])) { $amount = count($dataset['values']) > 1 ? $dataset['burndown']['maxEstimation'] / (count($dataset['values']) - 1) : 0; for ($i = 0; $i < count($dataset['values']); $i++) { $burndownValues[] = $dataset['burndown']['maxEstimation'] - $i * $amount; } $DataSet->AddPoint($burndownValues, "Burndown" . $ds_id, $dataset['burndown']['maxEstimation']); } } $DataSet->AddAllSeries(); if (isset($this->labels)) { $DataSet->AddPoint($this->labels, "Labels"); $DataSet->SetAbsciseLabelSerie("Labels"); } else { $DataSet->SetAbsciseLabelSerie(); } foreach ($this->datasets as $ds_id => $dataset) { $DataSet->SetSerieName($dataset['label'], "Serie" . $ds_id); if (isset($dataset['burndown'])) { $DataSet->SetSerieName($dataset['burndown']['label'], "Burndown" . $ds_id); } } if (isset($this->values_title)) { $DataSet->SetYAxisName($this->values_title); } if (isset($this->labels_title)) { $DataSet->SetXAxisName($this->labels_title); } // Initialise the graph $Test = new pChart($this->width, $this->height); $Test->setFixedScale(0, ceil(max($maxvals) / 5) * 5); $Test->setFontProperties(THEBUGGENIE_MODULES_PATH . 'pchart' . DS . 'fonts' . DS . 'DroidSans.ttf', 8); if (isset($this->labels_title)) { $Test->setGraphArea(50, 30, $this->width - 30, $this->height - 45); } else { $Test->setGraphArea(50, 30, $this->width - 30, $this->height - 30); } $Test->drawFilledRoundedRectangle(2, 2, $this->width - 3, $this->height - 3, 5, 240, 240, 240); $Test->drawRoundedRectangle(0, 0, $this->width - 1, $this->height - 1, 5, 230, 230, 230); $Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2); $Test->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the 0 line $Test->setFontProperties(THEBUGGENIE_MODULES_PATH . 'pchart' . DS . 'fonts' . DS . 'DroidSans.ttf', 6); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the cubic curve graph if (isset($this->style) && $this->style == 'curved') { $Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription()); } elseif (isset($this->style) && $this->style == 'filled_line') { $Test->drawFilledLineGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 50, true); } elseif (isset($this->style) && $this->style == 'stacked_bar') { $Test->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 50, true); } elseif (isset($this->style) && $this->style == 'single_bar') { $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE); } else { $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); } if (isset($this->include_plotter) && $this->include_plotter) { $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255); } // Finish the graph $Test->setFontProperties(THEBUGGENIE_MODULES_PATH . 'pchart' . DS . 'fonts' . DS . 'DroidSans.ttf', 8); //$Test->drawLegend(600, 30, $DataSet->GetDataDescription(), 255, 255, 255); $Test->drawLegend(55, 35, $DataSet->GetDataDescription(), 255, 255, 255); $Test->setFontProperties(THEBUGGENIE_MODULES_PATH . 'pchart' . DS . 'fonts' . DS . 'DroidSansBold.ttf', 10); $Test->drawTitle(50, 22, $this->title, 50, 50, 50, $this->width - 30); $Test->Stroke(); //("example2.png"); }
/** * @author Patrick plichart * @param string localgraphid an identifier for the graph to be displayed * @param array $datax a flat sery of x labels * @param array $setOfySeries an array of y series to be drawn (needs to be consistent with xsery), keys indicates the legend title * @param string $title the title of the graph * @param string xAxisLabel label of the x Axis * @param string yAxisLabel label of the y Axis * @return string the url of the generated graph */ private function getChart($localGraphId, $datax, $setOfySeries, $title, $type = "bar", $xAxisLabel = "", $yAxisLabel = "", $r = "208", $g = "2", $b = "57") { // Dataset definition if (count($datax) == 0) { throw new \common_exception_NoContent("Empty data set"); } $dataSet = new \pData(); foreach ($setOfySeries as $legend => $ysery) { $dataSet->AddPoint($ysery, $legend); $dataSet->SetSerieName($legend, $legend); } $dataSet->AddAllSeries(); $dataSet->AddPoint($datax, "xLabels"); $dataSet->SetYAxisName($yAxisLabel); $dataSet->SetXAxisName($xAxisLabel); $dataSet->SetAbsciseLabelSerie("xLabels"); // Initialise the graph $graph = new \pChart(490, 260); $graph->createColorGradientPalette($r, $g, $b, $r, $g, $b, 5); // aa is way too slow here $graph->Antialias = false; $graph->setFontProperties(fontName, 8); $graph->setGraphArea(55, 40, 450, 200); // draw the background rectangle $graph->drawFilledRoundedRectangle(7, 7, 655, 253, 5, 240, 240, 240); $graph->drawRoundedRectangle(5, 5, 655, 225, 5, 230, 230, 230); $graph->drawGraphArea(255, 255, 255, true); $graph->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, true, 0, 2, true); $graph->drawGrid(4, true, 230, 230, 230, 50); // Draw the 0 line $graph->setFontProperties(fontName, 6); $graph->drawTreshold(0, 143, 55, 72, true, true); // Draw the bar graph switch ($type) { case "bar": $graph->drawBarGraph($dataSet->GetData(), $dataSet->GetDataDescription(), true); break; case "line": $graph->drawLineGraph($dataSet->GetData(), $dataSet->GetDataDescription()); $graph->drawPlotGraph($dataSet->GetData(), $dataSet->GetDataDescription(), 3, 2, 255, 255, 255); break; } // Finish the graph $graph->setFontProperties(fontName, 9); $graph->drawLegend(50, 220, $dataSet->GetDataDescription(), 254, 254, 254); $graph->setFontProperties(fontName, 8); $graph->drawTitle(15, 30, $title, 50, 80, 50); $url = $this->getUniqueMediaFileName($localGraphId, "png"); $graph->Render(ROOT_PATH . $url); return ROOT_URL . $url; }
require 'DB.php'; require 'graphfunc.php'; $name = $_GET['name']; preg_replace("/[^A-Za-z0-9 ]/", '', $name); $db = DB::connect("mysql://*****:*****@localhost/games"); $sql = "select games.date, elo.elo from elo inner join games on games.gameid = elo.gameid where elo.name = '{$name}' order by elo.eloid asc"; $q = $db->query($sql); $date = array(); $val = array(); $year = 0; while ($q->fetchInto($row)) { if ($year != toYStr($row[0])) { $date[] = toYStr($row[0]); } else { $date[] = ""; } $year = toYStr($row[0]); $val[] = $row[1]; } // Standard inclusions include "pChart/pData.class"; include "pChart/pChart.class"; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint($val, "Serie1"); $DataSet->AddPoint($date, "Serie2"); $DataSet->AddSerie("Serie1"); $DataSet->SetAbsciseLabelSerie("Serie2"); $DataSet->SetYAxisName("ELO"); $DataSet->SetXAxisName("Game"); drawChart($title, $DataSet, "line", array(array(255, 0, 0)));
// Standard inclusions include "pChart/pData.class"; include "pChart/pChart.class"; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint($myarr, "Serie1"); $DataSet->AddPoint($myarr1, "Serie2"); $DataSet->AddPoint(array(Jan, Feb, Mar, Apr, May), "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);
protected function generateGraphImage($finalData, $hourflag, $title = 'Sticky Charts', $x_axis_format = 'date') { $path = $this->config->item('csv_upload_path'); if (!empty($finalData['data'])) { $DataSet = new pData(); $in = 0; foreach ($finalData['data'] as $seriesData) { $in++; $seriesIndex = 'Serie' . $in; $DataSet->AddPoint($seriesData['data'], $seriesIndex); $DataSet->SetSerieName($seriesData['name'], $seriesIndex); $DataSet->AddSerie($seriesIndex); } $xAxisArray = array(); $in++; $seriesIndex = 'Serie' . $in; $catCount = count($finalData['cat']); if ($catCount <= 10) { $DataSet->SetXAxisFormat($x_axis_format); } foreach ($finalData['cat'] as $catD) { if ($catCount > 10) { $xAxisArray[] = ''; } else { $xAxisArray[] = strtotime($catD); } } $DataSet->SetYAxisFormat("number"); $DataSet->AddPoint($xAxisArray, $seriesIndex); $DataSet->SetAbsciseLabelSerie($seriesIndex); $DataSet->SetYAxisName($finalData['y_title']); $DataSet->SetXAxisName($finalData['x_title']); // Initialise the graph $Test = new pChart(985, 458); $Test->drawBackground(247, 226, 180); $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 8); $Test->setGraphArea(40, 30, 950, 400); $Test->drawGraphArea(109, 110, 114, false); $Test->drawGrid(4, false, 0, 0, 0, 50); $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 6); // Draw the line graph if ($title == 'Violation Report') { //!$hourflag && $sCount = count($finalData['data']); if ($sCount > 0) { for ($m = 0; $m < $sCount; $m++) { $color = Color_handler::get_next($m); $rgb = $color->get_rgb(); $Test->setColorPalette($m, $rgb['r'], $rgb['g'], $rgb['b']); } } $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 0, 0, 0, TRUE, 0, 0, TRUE); $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription()); } else { $sCount = count($finalData['data']); if ($sCount > 0) { for ($m = 0; $m < $sCount; $m++) { $color = Color_handler::get_next($m % 3); $rgb = $color->get_rgb(); $Test->setColorPalette($m, $rgb['r'], $rgb['g'], $rgb['b']); } } $Test->setLineStyle(2); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 0, 0, 0, TRUE, 0, 2); $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription()); $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 2); } // Finish the graph $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 8); $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 10); $imgName = uniqid('graph_') . '.png'; $Test->Render($path . $imgName); return upload_to_amazon_graphImage($imgName, $path); } }
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"); }
/** * 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; }
/** * This method return a content html, it's used inside get_block method for showing it inside dashboard interface * @return string content html */ public function get_teachers_information_graph() { $teachers = $this->teachers; $graph = ''; $user_ids = array_keys($teachers); $a_last_week = get_last_week(); if (is_array($user_ids) && count($user_ids) > 0) { $data_set = new pData(); foreach ($user_ids as $user_id) { $teacher_info = api_get_user_info($user_id); $username = $teacher_info['username']; $time_by_days = array(); foreach ($a_last_week as $day) { // day is received as y-m-d 12:00:00 $start_date = api_get_utc_datetime($day); $end_date = api_get_utc_datetime($day + (3600 * 24 - 1)); $time_on_platform_by_day = Tracking::get_time_spent_on_the_platform($user_id, 'custom', $start_date, $end_date); $hours = floor($time_on_platform_by_day / 3600); $min = floor(($time_on_platform_by_day - $hours * 3600) / 60); $time_by_days[] = $min; } $data_set->AddPoint($time_by_days, $username); $data_set->AddSerie($username); } $last_week = date('Y-m-d', $a_last_week[0]) . ' ' . get_lang('To') . ' ' . date('Y-m-d', $a_last_week[6]); $days_on_week = array(); foreach ($a_last_week as $weekday) { $days_on_week[] = date('d/m', $weekday); } $data_set->AddPoint($days_on_week, "Days"); $data_set->SetXAxisName($last_week); $data_set->SetYAxisName(get_lang('Minutes')); $data_set->SetAbsciseLabelSerie("Days"); $graph_id = $this->user_id . 'TeacherConnectionsGraph'; $cache = new pCache(); // the graph id $data = $data_set->GetData(); if ($cache->IsInCache($graph_id, $data_set->GetData())) { //if we already created the img $img_file = $cache->GetHash($graph_id, $data_set->GetData()); } else { // Initializing the graph $bg_width = 440; $bg_height = 350; $test = new pChart($bg_width + 10, $bg_height + 20); $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 8); $test->setGraphArea(65, 30, $bg_width - 70, $bg_height - 50); $test->drawFilledRoundedRectangle(7, 7, $bg_width, $bg_height, 5, 240, 240, 240); $test->drawRoundedRectangle(5, 5, $bg_width + 2, $bg_height + 2, 5, 230, 230, 230); $test->drawGraphArea(255, 255, 255, TRUE); $test->drawScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE); $test->drawGrid(4, TRUE, 230, 230, 230, 50); // Drawing lines //$test->drawLineGraph($data_set->GetData(),$data_set->GetDataDescription()); $test->drawFilledCubicCurve($data_set->GetData(), $data_set->GetDataDescription(), 0.1, 30); //$test->drawPlotGraph($data_set->GetData(),$data_set->GetDataDescription(),3,2,255,255,255); // Drawing Legend $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 8); $test->drawLegend($bg_width - 80, 20, $data_set->GetDataDescription(), 204, 204, 255); $test->writeValues($data_set->GetData(), $data_set->GetDataDescription(), array("Days")); $cache->WriteToCache($graph_id, $data_set->GetData(), $test); ob_start(); $test->Stroke(); ob_end_clean(); $img_file = $cache->GetHash($graph_id, $data_set->GetData()); } if (!empty($img_file)) { $graph = '<img src="' . api_get_path(WEB_ARCHIVE_PATH) . $img_file . '">'; } } else { $graph = '<p>' . api_convert_encoding(get_lang('GraphicNotAvailable'), 'UTF-8') . '</p>'; } return $graph; }
} //Close the connection fclose($handle); // Include Global Config include "../conf/graph_conf.php"; // Standard inclusions include "{$pChart_path}/pData.class"; include "{$pChart_path}/pChart.class"; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint($ydata, "Serie1"); $DataSet->AddPoint($xdata, "Serie3"); $DataSet->AddSerie("Serie1"); $DataSet->SetAbsciseLabelSerie("Serie3"); $DataSet->SetYAxisName("Usage"); $DataSet->SetXAxisName("Hour"); $DataSet->SetYAxisUnit("%"); #$DataSet->SetXAxisFormat("date"); // Initialise the graph $Test = new pChart(900, 225); $Test->setColorPalette(0, 126, 185, 245); $Test->setFontProperties("{$font}", 8); $Test->setGraphArea(75, 35, 890, 190); #$Test->drawFilledRoundedRectangle(7,7,450,223,5,240,240,240); #$Test->drawRoundedRectangle(5,5,450,225,5,230,230,230); $Test->drawGraphArea(255, 255, 255, FALSE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 75, 75, 75, TRUE, 0, 2); $Test->drawGrid(1, TRUE, 240, 240, 240); #$Test->drawGrid(4,TRUE); // Draw the 0 line $Test->setFontProperties("{$font}", 6);
function showGraph($searchInfo = '') { $conditions = empty($searchInfo['keywordId']) ? "" : " and s.keyword_id=" . intval($searchInfo['keywordId']); $conditions .= empty($searchInfo['seId']) ? "" : " and s.searchengine_id=" . intval($searchInfo['seId']); $sql = "select s.*,se.domain \r\n\t\t\t\t\tfrom searchresults s,searchengines se \r\n\t\t\t\t\twhere s.searchengine_id=se.id \r\n\t\t\t\t\tand time>= " . intval($searchInfo['fromTime']) . " and time<" . intval($searchInfo['toTime']) . " {$conditions} \r\n\t\t\t\t\torder by s.time"; $repList = $this->db->select($sql); $reportList = array(); $seList = array(); foreach ($repList as $repInfo) { $var = $repInfo['searchengine_id'] . $repInfo['keyword_id'] . $repInfo['time']; if (empty($reportList[$var])) { $reportList[$var] = $repInfo; } else { if ($repInfo['rank'] < $reportList[$var]['rank']) { $reportList[$var] = $repInfo; } } if (empty($seList[$repInfo['searchengine_id']])) { $seList[$repInfo['searchengine_id']] = $repInfo['domain']; } } asort($seList); $dataList = array(); $maxValue = 0; foreach ($reportList as $repInfo) { $seId = $repInfo['searchengine_id']; $dataList[$repInfo['time']][$seId] = $repInfo['rank']; $maxValue = $repInfo['rank'] > $maxValue ? $repInfo['rank'] : $maxValue; } // check whether the records are available for drawing graph if (empty($dataList) || empty($maxValue)) { $kpText = $_SESSION['lang_code'] == 'ja' ? $_SESSION['text']['common']['No Records Found'] . "!" : "No Records Found!"; $this->showMessageAsImage($kpText); } # Dataset definition $dataSet = new pData(); foreach ($dataList as $dataInfo) { $i = 1; foreach ($seList as $seId => $seVal) { $val = empty($dataInfo[$seId]) ? 0 : $dataInfo[$seId]; $dataSet->AddPoint($val, "Serie" . $i++); } } $i = 1; foreach ($seList as $seDomain) { $dataSet->AddSerie("Serie{$i}"); $dataSet->SetSerieName($seDomain, "Serie{$i}"); $i++; } $serieCount = count($seList) + 1; $dataSet->AddPoint(array_keys($dataList), "Serie{$serieCount}"); $dataSet->SetAbsciseLabelSerie("Serie{$serieCount}"); # if language is japanese if ($_SESSION['lang_code'] == 'ja') { $fontFile = "fonts/M+1P+IPAG.ttf"; $dataSet->SetXAxisName($_SESSION['text']['common']["Date"]); $dataSet->SetYAxisName($_SESSION['text']['common']["Rank"]); } else { $fontFile = "fonts/tahoma.ttf"; $dataSet->SetXAxisName("Date"); $dataSet->SetYAxisName("Rank"); } $dataSet->SetXAxisFormat("date"); # Initialise the graph $chart = new pChart(720, 520); $chart->setFixedScale($maxValue, 1); $chart->setFontProperties($fontFile, 8); $chart->setGraphArea(85, 30, 670, 425); $chart->drawFilledRoundedRectangle(7, 7, 713, 513, 5, 240, 240, 240); $chart->drawRoundedRectangle(5, 5, 715, 515, 5, 230, 230, 230); $chart->drawGraphArea(255, 255, 255, TRUE); $chart->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 90, 2); $chart->drawGrid(4, TRUE, 230, 230, 230, 50); # Draw the 0 line $chart->setFontProperties($fontFile, 6); $chart->drawTreshold(0, 143, 55, 72, TRUE, TRUE); # Draw the line graph $chart->drawLineGraph($dataSet->GetData(), $dataSet->GetDataDescription()); $chart->drawPlotGraph($dataSet->GetData(), $dataSet->GetDataDescription(), 3, 2, 255, 255, 255); $j = 1; $chart->setFontProperties($fontFile, 10); foreach ($seList as $seDomain) { $chart->writeValues($dataSet->GetData(), $dataSet->GetDataDescription(), "Serie" . $j++); } # Finish the graph $chart->setFontProperties("fonts/tahoma.ttf", 8); $chart->drawLegend(90, 35, $dataSet->GetDataDescription(), 255, 255, 255); $chart->setFontProperties($fontFile, 10); $kpText = $_SESSION['lang_code'] == 'ja' ? $this->spTextKeyword["Keyword Position Report"] : "Keyword Position Report"; $chart->drawTitle(60, 22, $kpText, 50, 50, 50, 585); $chart->stroke(); }
/* Example18 : Missing values */ // Standard inclusions include "src/pData.php"; include "src/pChart.php"; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint(array(2, 5, 7, "", "", 5, 6, 4, 8, 4, "", 2, 5, 6, 4, 5, 6, 7, 6), "Serie1"); $DataSet->AddPoint(array(-1, -3, -1, -2, -4, -1, "", -4, -5, -3, -2, -2, -3, -3, -5, -4, -3, -1, ""), "Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie(); $DataSet->SetSerieName("Raw #1", "Serie1"); $DataSet->SetSerieName("Raw #2", "Serie2"); $DataSet->SetYAxisName("Response time"); $DataSet->SetXAxisName("Sample #ID"); //print_r($DataSet->GetData()); // Initialise the graph $Test = new pChart(700, 230); $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(55, 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, 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 line graph $DataSet->RemoveSerie("Serie2");
include "pChart/pData.class"; include "pChart/pChart.class"; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint($wild_type, "Serie1"); $DataSet->AddPoint($hetero, "Serie2"); $DataSet->AddPoint($h**o, "Serie3"); $DataSet->AddPoint($snp, "Labels"); $DataSet->AddAllSeries(); $DataSet->RemoveSerie("Labels"); $DataSet->SetAbsciseLabelSerie("Labels"); $DataSet->SetSerieName("Wild type", "Serie1"); $DataSet->SetSerieName("Heterozygous variant", "Serie2"); $DataSet->SetSerieName("Homozygous variant", "Serie3"); $DataSet->SetYAxisName("Samples"); $DataSet->SetXAxisName("Drug related SNPs"); // Initialise the graph $Test = new pChart(910, 400); #设置画布大小 $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(60, 30, 750, 350); #这个是设置图像大小的 $Test->drawFilledRoundedRectangle(7, 7, 903, 393, 5, 240, 240, 240); #设置边框大小 #Test->drawRoundedRectangle(5,5,853,393,5,230,230,230); $Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALLSTART0, 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(2,143,55,72,TRUE,TRUE);
function main() { $ThisArea = array('1' => 'Orizaba', '2' => 'Guadalajara', '3' => 'Ramos Arizpe', '4' => 'Tijuana'); if (!$this->args) { $this->help(); $this->err(__('Usage report <year> <area> <month> <fraction> <all_areas> ', true)); $this->_stop(); } $KmsConditions = null; if (isset($this->args[0]) && !isset($this->args[3])) { $CurrentYear = $this->args[0]; $KmsConditions['KmsCurrent.fecha_guia LIKE'] = "%" . $CurrentYear . "%"; } if (isset($this->args[1])) { $KeyArea = $this->args[1]; $KmsConditions['KmsCurrent.id_area'] = $KeyArea; } else { $KeyArea = null; } if (isset($this->args[2])) { $CurrentMonth = $this->args[2]; $CurrentYear = $this->args[0]; $KmsConditions['KmsCurrent.fecha_guia LIKE'] = "%" . $CurrentYear . "-" . $CurrentMonth . "%"; } else { $CurrentMonth = null; } if (isset($this->args[3])) { $Fraccion = $this->args[3]; $KmsConditions['KmsCurrent.id_fraccion'] = $Fraccion; } else { $Fraccion = null; } if (isset($this->args[4])) { $all = $this->args[4]; } else { $all = null; } $args = $this->args; /** ALERT Like in the ancient times Define the vars firts **/ // $KmsConditions = null; // $this->out(pr($KmsConditions)); // $this->out(pr($args));exit(); $NumDays = date('t', mktime('0', '0', '0', $CurrentMonth, '01', $CurrentYear)); /** TODO => Firts we need all areas => all fractions => CurrentYear ** => Second Detail By Four Areas => CurrentYear ** => Third Graphics by Area => Month => Fraction => CurrentYear **/ $kms_full = $full = $kms_all = null; $kms_search = $this->KmsCurrent->find('all', array('conditions' => $KmsConditions)); // $this->out(pr($KmsConditions)); // $this->out(pr($kms_search)); // exit(); if (!empty($kms_search)) { foreach ($kms_search as $key => $value) { if ($value['KmsCurrent']['id_configuracionviaje'] == '3') { $kms_full[$value['KmsCurrent']['no_viaje']][] = $value['KmsCurrent']['kms_viaje']; $kms_full[$value['KmsCurrent']['no_viaje']]['day'] = substr($value['KmsCurrent']['fecha_guia'], 8, 2); } elseif ($value['KmsCurrent']['id_configuracionviaje'] == '2' or $value['KmsCurrent']['id_configuracionviaje'] == '1') { $kms_all += $value['KmsCurrent']['kms_viaje']; $kms_senc[substr($value['KmsCurrent']['fecha_guia'], 8, 2)] = $value['KmsCurrent']['kms_viaje']; } } foreach ($kms_full as $k => $data) { $full += $data['0']; $full_days[$data['day']] += $data['0']; } $AreaCorp['kms_all'] = ($kms_all + $full) * 2; $all_days = ($kms_all + array_sum($full_days)) * 2; } else { $AreaCorp['kms_all'] = null; } // $this->out(pr($full)); $this->out(pr($full_days)); // $this->out(array_sum($full_days)); $this->out(pr($kms_senc)); $this->out(pr($AreaCorp)); $this->out(pr($all_days)); // exit(); $report_day = $kms_senc; $report_year = array(); /** ALERT Save the result for Display in the view */ //2 $this->autoRender = false; //3 App::import('Vendor', 'pData', array('file' => 'pchart' . DS . 'pData.class')); App::import('Vendor', 'pChart', array('file' => 'pchart' . DS . 'pChart.class')); //4 $fontFolder = APP . 'vendors' . DS . 'pchart' . DS . 'Fonts'; $fontFolder = '..' . DS . '..' . DS . 'vendors' . DS . 'pchart' . DS . 'Fonts'; //5 // Dataset definition $DataSet = new pData(); $MaxKms = max($report_day); $MaxKms = $MaxKms + 100; foreach ($report_day as $key => $value) { $MyDay[] = (int) $key; } // $this->out(pr($MyDay)); $DataSet->AddPoint($report_day, "Serie1"); // $DataSet->AddPoint('4',"Serie2"); // $DataSet->AddPoint('20',"Serie3"); // $DataSet->AddPoint($MyDay,"Name"); // exit(); // $this->out(pr($DataSet->GetData())); // $idx=0; // foreach($MyDay as $key => $value){ // $DataSet->AddPoint($value,"Serie1"); // $DataSet->AddPoint((int)$key,"Name"); // } // $this->out(pr($MyDay)); // $DataSet->GetData()['0']['Name']=; // $DataSet->GetData()['0']['Name']=1; $this->out(pr($DataSet->GetData())); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie(); $key = $value = null; $DataSet->SetSerieName("Kilometros", "Serie1"); $DataSet->SetSerieName("Dia", "Serie2"); $DataSet->SetYAxisName("Kilometros Dias"); $DataSet->SetYAxisUnit("Kms"); $DataSet->SetXAxisName("Dias"); $DataSet->SetXAxisFormat("number"); // Initialise the graph // pr($SchemaFolder); $Test = new pChart(820, 260); $Test->setFixedScale(1, $MaxKms, 5, 0, $NumDays, 5); $Test->setDateFormat("H:m"); $Test->setFontProperties($fontFolder . DS . "tahoma.ttf", 10); // $Test->setColorPalette(0,115,173,207); // $Test->setColorPalette(1,144,196,226); $Test->setColorPalette(2, 174, 216, 240); $Test->setColorPalette(3, 64, 140, 195); $Test->setColorPalette(4, 104, 188, 209); $Test->setColorPalette(5, 99, 200, 226); $Test->setColorPalette(6, 82, 124, 148); $Test->setColorPalette(7, 97, 152, 183); $Test->setColorPalette(8, 105, 210, 231); $Test->setColorPalette(9, 167, 219, 216); $Test->setColorPalette(10, 224, 228, 204); $Test->setColorPalette(11, 243, 134, 48); // $Test->loadColorPalette("/tmp/schema/blue.txt",","); $Test->setGraphArea(100, 30, 790, 200); // $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); $Test->drawRoundedRectangle(5, 5, 810, 225, 5, 230, 230, 230); $Test->drawGraphArea(255, 255, 255, TRUE); // dibujar la grafica $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 line graph // Draw the 0 line $Test->setFontProperties($fontFolder . DS . "tahoma.ttf", 10); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the bar graph $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE, 80); // $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription()); // $Test->drawXYPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","Serie2"); // $Test->drawXYPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","Serie3"); // $Test->drawXYGraph($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","Serie2"); // Finish the graph $today = date('Y-m-d'); // $Test->setFontProperties($fontFolder.DS."tahoma.ttf",8); // $Test->drawLegend(820,150,$DataSet->GetDataDescription(),255,255,255); $Test->setFontProperties($fontFolder . DS . "tahoma.ttf", 10); // $_today = if (isset($KeyArea)) { $area = "_" . $KeyArea; } else { $area = "_0"; } if (isset($Fraccion)) { $fraction = "_" . $Fraccion; } else { $fraction = "_0"; } $Test->drawTitle(220, 22, "Kilometros {$ThisArea[$KeyArea]} {$MyMonth} {$CurrentYear}", 50, 50, 50, 585); $Test->Render("../../app/webroot/img/thumbs/graph_kms_" . $today . $area . $fraction . ".png"); }
function showGraph($searchInfo = '') { $conditions = empty($searchInfo['keywordId']) ? "" : " and s.keyword_id=" . $searchInfo['keywordId']; $conditions .= empty($searchInfo['seId']) ? "" : " and s.searchengine_id=" . $searchInfo['seId']; $sql = "select s.*,se.domain \r\n\t\t\t\t\tfrom searchresults s,searchengines se \r\n\t\t\t\t\twhere s.searchengine_id=se.id \r\n\t\t\t\t\tand time>= {$searchInfo['fromTime']} and time<{$searchInfo['toTime']} {$conditions} \r\n\t\t\t\t\torder by s.time"; $repList = $this->db->select($sql); $reportList = array(); $seList = array(); foreach ($repList as $repInfo) { $var = $repInfo['searchengine_id'] . $repInfo['keyword_id'] . $repInfo['time']; if (empty($reportList[$var])) { $reportList[$var] = $repInfo; } else { if ($repInfo['rank'] < $reportList[$var]['rank']) { $reportList[$var] = $repInfo; } } if (empty($seList[$repInfo['searchengine_id']])) { $seList[$repInfo['searchengine_id']] = $repInfo['domain']; } } asort($seList); $dataList = array(); foreach ($reportList as $repInfo) { $seId = $repInfo['searchengine_id']; $dataList[$repInfo['time']][$seId] = $repInfo['rank']; } # Dataset definition $dataSet = new pData(); foreach ($dataList as $dataInfo) { $i = 1; foreach ($seList as $seId => $seVal) { $val = empty($dataInfo[$seId]) ? 0 : $dataInfo[$seId]; $dataSet->AddPoint($val, "Serie" . $i++); } } $i = 1; foreach ($seList as $seDomain) { $dataSet->AddSerie("Serie{$i}"); $dataSet->SetSerieName($seDomain, "Serie{$i}"); $i++; } $serieCount = count($seList) + 1; $dataSet->AddPoint(array_keys($dataList), "Serie{$serieCount}"); $dataSet->SetAbsciseLabelSerie("Serie{$serieCount}"); $dataSet->SetXAxisName("Date"); $dataSet->SetYAxisName("Rank"); $dataSet->SetXAxisFormat("date"); # Initialise the graph $chart = new pChart(720, 520); $chart->setFontProperties("fonts/tahoma.ttf", 8); $chart->setGraphArea(85, 30, 670, 425); $chart->drawFilledRoundedRectangle(7, 7, 713, 513, 5, 240, 240, 240); $chart->drawRoundedRectangle(5, 5, 715, 515, 5, 230, 230, 230); $chart->drawGraphArea(255, 255, 255, TRUE); $chart->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 90, 2); $chart->drawGrid(4, TRUE, 230, 230, 230, 50); # Draw the 0 line $chart->setFontProperties("fonts/tahoma.ttf", 6); $chart->drawTreshold(0, 143, 55, 72, TRUE, TRUE); # Draw the line graph $chart->drawLineGraph($dataSet->GetData(), $dataSet->GetDataDescription()); $chart->drawPlotGraph($dataSet->GetData(), $dataSet->GetDataDescription(), 3, 2, 255, 255, 255); $j = 1; $chart->setFontProperties("fonts/tahoma.ttf", 10); foreach ($seList as $seDomain) { $chart->writeValues($dataSet->GetData(), $dataSet->GetDataDescription(), "Serie" . $j++); } # Finish the graph $chart->setFontProperties("fonts/tahoma.ttf", 8); $chart->drawLegend(90, 35, $dataSet->GetDataDescription(), 255, 255, 255); $chart->setFontProperties("fonts/tahoma.ttf", 10); $chart->drawTitle(60, 22, "Keyword Position Report", 50, 50, 50, 585); $chart->stroke(); }
// Standard inclusions include "pChart/pData.class"; include "pChart/pChart.class"; // Dataset definition $DataSet = new pData(); // $DataSet->AddPoint(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->AddPoint(array(0,3.4,6.4,8.7,9.8,9.8,8.7,6.4,3.4,0,-3.4,-6.4,-8.6,-9.8,-9.9),"Serie2"); $DataSet->AddPoint(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->AddPoint(array("Jan","Jan","Jan","Feb","Feb","Feb","Mar","Mar","Mar","Apr","Apr","Apr","May","May","May"),"Serie4"); $DataSet->AddAllSeries(); // $DataSet->SetAbsciseLabelSerie("Serie4"); // $DataSet->SetSerieName("Max Average","Serie1"); // $DataSet->SetSerieName("Min Average","Serie2"); $DataSet->SetSerieName("Temperature", "Serie3"); $DataSet->SetYAxisName("Kg"); $DataSet->SetXAxisName("week"); // Initialise the graph $Test = new pChart(600, 230); $Test->reportWarnings("GD"); $Test->setFixedScale(-12, 13, 5); // $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(65, 20, 570, 185); $Test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 243, 249, 249); $Test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230); $Test->drawGraphArea(243, 249, 249, TRUE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE, 3); $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);
} } if (!empty($charttype)) { if ($charttype == 'summary') { $chartdata = new pData(); $chartdata->AddPoint($chartnotstarted, "Serie1"); $chartdata->AddPoint($chartinprogress, "Serie2"); $chartdata->AddPoint($chartcompleted, "Serie3"); $chartdata->AddPoint($chartname, "Serie4"); $chartdata->AddAllSeries(); $chartdata->SetAbsciseLabelSerie("Serie4"); $chartdata->SetSerieName(get_string('notstartedusers', 'local_report_completion'), "Serie1"); $chartdata->SetSerieName(get_string('inprogressusers', 'local_report_completion'), "Serie2"); $chartdata->SetSerieName(get_string('completedusers', 'local_report_completion'), "Serie3"); $chartdata->SetYAxisName(get_string('numusers', 'local_report_completion')); $chartdata->SetXAxisName(get_string('course')); } else { if ($charttype == 'course') { $chartdata = new pData(); $chartdata->AddPoint($seriesdata, "Serie1"); $chartdata->AddPoint(array(get_string('notstartedusers', 'local_report_completion'), get_string('inprogressusers', 'local_report_completion'), get_string('completedusers', 'local_report_completion')), "Serie2"); $chartdata->AddAllSeries(); $chartdata->SetAbsciseLabelSerie("Serie2"); } } } if (empty($dodownload) && empty($showchart)) { echo html_writer::table($coursecomptable); if (!empty($courseid) && empty($charttype)) { echo $completiontypeselectoutput; }
// Standard inclusions include "src/pData.php"; include "src/pChart.php"; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint(array(1, 2, 5), "Serie1"); $DataSet->AddPoint(array(3, 2, 2), "Serie2"); $DataSet->AddPoint(array(3, 4, 1), "Serie3"); $DataSet->AddPoint(array("A#~1", "A#~2", "A#~3"), "Labels"); $DataSet->AddAllSeries(); $DataSet->RemoveSerie("Labels"); $DataSet->SetAbsciseLabelSerie("Labels"); $DataSet->SetSerieName("Alpha", "Serie1"); $DataSet->SetSerieName("Beta", "Serie2"); $DataSet->SetSerieName("Gama", "Serie3"); $DataSet->SetXAxisName("Samples IDs"); $DataSet->SetYAxisName("Test Marker"); $DataSet->SetYAxisUnit("µm"); // Initialise the graph $Test = new pChart(380, 400); $Test->drawGraphAreaGradient(90, 90, 90, 90, TARGET_BACKGROUND); // Graph area setup $Test->setFontProperties("Fonts/pf_arma_five.ttf", 6); $Test->setGraphArea(110, 180, 350, 360); $Test->drawGraphArea(213, 217, 221, FALSE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALLSTART0, 213, 217, 221, TRUE, 0, 2, TRUE); $Test->drawGraphAreaGradient(40, 40, 40, -50); $Test->drawGrid(4, TRUE, 230, 230, 230, 5); // Draw the title $Test->setFontProperties("Fonts/tahoma.ttf", 10); $Title = " Average growth size for selected\r\n DNA samples ";
/** * Creates the object and prepares it for rendering. * Does all the calculation like borders, margins, paddings .... * * @return void */ private function preGraphCreation() { // Initialize the graph $this->objChart = new pChart($this->intWidth, $this->intHeight); //set the color palette to be used foreach ($this->arrDefaultColorPalette as $intKey => $strCurrentColor) { $arrCurColor = hex2rgb($strCurrentColor); $this->objChart->setColorPalette($intKey, $arrCurColor[0], $arrCurColor[1], $arrCurColor[2]); } //calculate all needed params, draw that funky shit //the outer bounding and pane - rounded and with sharp corners $arrBackgroundColor = hex2rgb($this->strBackgroundColor); if ($this->bitRoundedCorners) { $this->objChart->drawFilledRoundedRectangle(2, 2, $this->intWidth - 3, $this->intHeight - 3, 5, $arrBackgroundColor[0], $arrBackgroundColor[1], $arrBackgroundColor[2]); $arrOuterBack = hex2rgb($this->strOuterFrameColor); $this->objChart->drawRoundedRectangle(0, 0, $this->intWidth - 1, $this->intHeight - 1, 5, $arrOuterBack[0], $arrOuterBack[1], $arrOuterBack[2]); } else { $this->objChart->drawFilledRectangle(0, 0, $this->intWidth, $this->intHeight, $arrBackgroundColor[0], $arrBackgroundColor[1], $arrBackgroundColor[2]); } //the graph area - x and or y-axis label present? if ($this->bitRenderLegend) { $intRightMargin = 10; } else { $intRightMargin = 20; } $intTopMargin = 15; $intBottomMargin = 30; $intLeftMargin = 40; $intLegendWidth = 0; if ($this->bitRenderLegend) { $intLegendWidth = 120; } $intWidth = $this->intWidth - $intRightMargin - $intLegendWidth; $intHeight = $this->intHeight - $intBottomMargin; $intLeftStart = $intLeftMargin; $intTopStart = $intTopMargin; if ($this->strYAxisTitle != "") { $intLeftStart += 15; //$intWidth -= 15; //TODO: why not needed? } if ($this->strXAxisTitle != "") { $intHeight -= 15; } if ($this->strGraphTitle != "") { //$intHeight -= 12; //TODO: why not needed??? $intTopStart += 12; } if ($this->intCurrentGraphMode != $this->GRAPH_TYPE_PIE) { $this->objChart->setGraphArea($intLeftStart, $intTopStart, $intWidth, $intHeight); $arrPaneBackground = hex2rgb($this->strGraphBackgroundColor); $this->objChart->drawGraphArea($arrPaneBackground[0], $arrPaneBackground[1], $arrPaneBackground[2], true); } $arrFontColors = hex2rgb($this->strFontColor); $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 8); //set up the axis-titles if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_BAR || $this->intCurrentGraphMode == $this->GRAPH_TYPE_STACKEDBAR || $this->intCurrentGraphMode == $this->GRAPH_TYPE_LINE) { if ($this->strXAxisTitle != "") { $this->objDataset->SetXAxisName($this->strXAxisTitle); } if ($this->strYAxisTitle != "") { $this->objDataset->SetYAxisName($this->strYAxisTitle); } } //the x- and y axis, in- / exclusive margins if ($this->bitAdditionalDatasetAdded && $this->bitScaleFromAdditionalDataset) { $this->objChart->drawScale($this->objAdditionalDataset->GetData(), $this->objAdditionalDataset->GetDataDescription(), SCALE_START0, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, true); } else { if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_BAR) { $this->objChart->drawScale($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), SCALE_START0, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, true); } else { if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_STACKEDBAR) { $this->objChart->drawScale($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), SCALE_ADDALLSTART0, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, true); } else { if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_LINE) { $this->objChart->drawScale($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), SCALE_NORMAL, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, false); } } } } //the background grid if ($this->intCurrentGraphMode != $this->GRAPH_TYPE_PIE) { $arrGridColor = hex2rgb($this->strGridColor); $this->objChart->drawGrid(4, true, $arrGridColor[0], $arrGridColor[1], $arrGridColor[2], 50); } if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_LINE) { // Draw the line graph $this->objChart->drawLineGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription()); //dots in line $this->objChart->drawPlotGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), 3, 2, 255, 255, 255); } else { if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_BAR) { //the zero-line $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 6); $this->objChart->drawBarGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), TRUE); $this->objChart->drawTreshold(0, 143, 55, 72, TRUE, TRUE); //if given, render the line-plots on top if ($this->bitAdditionalDatasetAdded) { //the line itself $this->objChart->drawLineGraph($this->objAdditionalDataset->GetData(), $this->objAdditionalDataset->GetDataDescription()); //the dots $this->objChart->drawPlotGraph($this->objAdditionalDataset->GetData(), $this->objAdditionalDataset->GetDataDescription(), 3, 2, 255, 255, 255); } } else { if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_STACKEDBAR) { //the zero-line $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 6); $this->objChart->drawTreshold(0, 143, 55, 72, TRUE, TRUE); $this->objChart->drawStackedBarGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), 75); } else { if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_PIE) { $this->objChart->drawPieGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), ceil($this->intWidth / 2) - 20, ceil($this->intHeight / 2), ceil($intHeight / 2) + 20, PIE_PERCENTAGE, TRUE, 50, 20, 5); } } } } //render values? if (count($this->arrValueSeriesToRender) > 0) { $this->objChart->writeValues($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), $this->arrValueSeriesToRender); } // Finish the graph $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 7); //set up the legend if ($this->bitRenderLegend) { if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_PIE) { $this->objChart->drawPieLegend($this->intWidth - $intLegendWidth - $intRightMargin + 10 - $this->intLegendAdditionalMargin, $intTopStart, $this->objDataset->GetData(), $this->objDataset->GetDataDescription(), 255, 255, 255); } else { $arrLegend = $this->objDataset->GetDataDescription(); //merge legends if ($this->bitAdditionalDatasetAdded) { $arrAdditionalLegend = $this->objAdditionalDataset->GetDataDescription(); foreach ($arrAdditionalLegend["Description"] as $strKey => $strName) { $arrLegend["Description"][$strKey] = $strName; } } $this->objChart->drawLegend($this->intWidth - $intLegendWidth - $intRightMargin + 10 - $this->intLegendAdditionalMargin, $intTopStart, $arrLegend, 255, 255, 255); } } //draw the title if ($this->strGraphTitle != "") { $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 10); $this->objChart->drawTitle(0, $intTopMargin, $this->strGraphTitle, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], $this->intWidth, 10); } }
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.'">'; } */ } }
<?php /* Example19 : Error reporting */ // Standard inclusions include "pChart/pData.class"; include "pChart/pChart.class"; // 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
function main() { $ThisArea = array('1' => 'Orizaba', '2' => 'Guadalajara', '3' => 'Ramos Arizpe', '4' => 'Tijuana'); if (!$this->args) { $this->help(); $this->err(__('Usage report <id_area> <id_fraccion> <year> <month> <all_areas> ', true)); $this->_stop(); } $KeyArea = $this->args[0]; $Fraccion = $this->args[1]; $CurrentYear = $this->args[2]; $CurrentMonth = $this->args[3]; $all = $this->args[4]; $args = $this->args; $this->out(pr($args)); $NumDays = date('t', mktime('0', '0', '0', $CurrentMonth, '01', $CurrentYear)); if (empty($all) && !empty($KeyArea) && !empty($CurrentMonth)) { // CurrentMonth Area $TonelajeConditions['TonelajeCurrent.fecha_guia LIKE'] = "%" . $CurrentYear . "-" . $CurrentMonth . "%"; $TonelajeConditions['TonelajeCurrent.id_area'] = $KeyArea; $TonelajeConditions['TonelajeCurrent.id_fraccion'] = $Fraccion; } if ($all == true && $KeyArea == false && $CurrentMonth == false) { // AllYear $TonelajeConditions['TonelajeCurrent.fecha_guia LIKE'] = "%" . $CurrentYear . "%"; $TonelajeConditions['TonelajeCurrent.id_fraccion'] = $Fraccion; } if ($all == true && $KeyArea > 0 && $CurrentMonth == false) { // AllYearArea $TonelajeConditions['TonelajeCurrent.fecha_guia LIKE'] = "%" . $CurrentYear . "%"; $TonelajeConditions['TonelajeCurrent.id_area'] = $KeyArea; $TonelajeConditions['TonelajeCurrent.id_fraccion'] = $Fraccion; } // $this->out(pr($TonelajeConditions));exit(); // $TonelajeConditions['TonelajeCurrent.fecha_guia LIKE'] = "%".$CurrentYear."-".$CurrentMonth."%"; // $TonelajeConditions['TonelajeCurrent.id_area'] = $KeyArea; // $TonelajeConditions['TonelajeCurrent.id_fraccion'] = $Fraccion; // $this->out(pr($TonelajeConditions));exit(); $report = $this->TonelajeCurrent->find('all', array('conditions' => $TonelajeConditions)); $toneladas = null; $report_day = array(); $report_year = array(); // $this->out(pr($report));exit(); foreach ($report as $key => $data) { if ($data['TonelajeCurrent']['status_guia'] == ' B') { $canceladas[] = $data; } $MyMonth = date('M', mktime('0', '0', '0', $CurrentMonth, '01', $CurrentYear)); // $this->out(pr($data)); // $report_day['00'] = '0'; if ($data['TonelajeCurrent']['status_guia'] !== ' B') { $toneladas += $data['TonelajeCurrent']['peso']; $counter[] = $data['TonelajeCurrent']['peso']; $day = substr($data['TonelajeCurrent']['fecha_guia'], 8, 2); $report_day[$day] += $data['TonelajeCurrent']['peso']; } } // End foreach $report /** ALERT Save the result for Display in the view */ // $this->out(pr($report_day));exit(); // $this->out($NumDays); // $this->out($MyMonth); // exit(); // $this->out(count($counter));exit(); //2 $this->autoRender = false; //3 App::import('Vendor', 'pData', array('file' => 'pchart' . DS . 'pData.class')); App::import('Vendor', 'pChart', array('file' => 'pchart' . DS . 'pChart.class')); //4 $fontFolder = APP . 'vendors' . DS . 'pchart' . DS . 'Fonts'; $fontFolder = '..' . DS . '..' . DS . 'vendors' . DS . 'pchart' . DS . 'Fonts'; // $SchemaFolder = APP.'vendors'.DS.'pchart'.DS.'schema'; //5 // Dataset definition $DataSet = new pData(); $MaxTons = max($report_day); $MaxTons = $MaxTons + 100; foreach ($report_day as $key => $value) { $MyDay[] = (int) $key; } // $this->out(pr($MyDay)); $DataSet->AddPoint($report_day, "Serie1"); // $DataSet->AddPoint('4',"Serie2"); // $DataSet->AddPoint('20',"Serie3"); // $DataSet->AddPoint($MyDay,"Name"); // exit(); // $this->out(pr($DataSet->GetData())); // $idx=0; // foreach($MyDay as $key => $value){ // $DataSet->AddPoint($value,"Serie1"); // $DataSet->AddPoint((int)$key,"Name"); // } // $this->out(pr($MyDay)); // $DataSet->GetData()['0']['Name']=; // $DataSet->GetData()['0']['Name']=1; $this->out(pr($DataSet->GetData())); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie(); $key = $value = null; $DataSet->SetSerieName("Toneladas", "Serie1"); $DataSet->SetSerieName("Dia", "Serie2"); $DataSet->SetYAxisName("Toneladas Dias"); $DataSet->SetYAxisUnit("Ton"); $DataSet->SetXAxisName("Dias"); $DataSet->SetXAxisFormat("number"); // Initialise the graph // pr($SchemaFolder); $Test = new pChart(820, 260); $Test->setFixedScale(1, $MaxTons, 5, 0, $NumDays, 5); $Test->setDateFormat("H:m"); $Test->setFontProperties($fontFolder . DS . "tahoma.ttf", 10); $Test->setColorPalette(0, 115, 173, 207); $Test->setColorPalette(1, 144, 196, 226); $Test->setColorPalette(2, 174, 216, 240); $Test->setColorPalette(3, 64, 140, 195); $Test->setColorPalette(4, 104, 188, 209); $Test->setColorPalette(5, 99, 200, 226); $Test->setColorPalette(6, 82, 124, 148); $Test->setColorPalette(7, 97, 152, 183); $Test->setColorPalette(8, 105, 210, 231); $Test->setColorPalette(9, 167, 219, 216); $Test->setColorPalette(10, 224, 228, 204); $Test->setColorPalette(11, 243, 134, 48); // $Test->loadColorPalette("/tmp/schema/blue.txt",","); $Test->setGraphArea(100, 30, 790, 200); // $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); $Test->drawRoundedRectangle(5, 5, 810, 225, 5, 230, 230, 230); $Test->drawGraphArea(255, 255, 255, TRUE); // dibujar la grafica $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 line graph // Draw the 0 line $Test->setFontProperties($fontFolder . DS . "tahoma.ttf", 10); $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the bar graph $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE, 80); // $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription()); // $Test->drawXYPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","Serie2"); // $Test->drawXYPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","Serie3"); // $Test->drawXYGraph($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","Serie2"); // Finish the graph $today = date('Y-m-d'); // $Test->setFontProperties($fontFolder.DS."tahoma.ttf",8); // $Test->drawLegend(820,150,$DataSet->GetDataDescription(),255,255,255); $Test->setFontProperties($fontFolder . DS . "tahoma.ttf", 10); if (empty($all) && !empty($KeyArea) && !empty($CurrentMonth)) { // CurrentMonth Area $Test->drawTitle(220, 22, "Toneladas {$ThisArea[$KeyArea]} {$MyMonth} {$CurrentYear}", 50, 50, 50, 585); $Test->Render("../../app/webroot/img/thumbs/graph_" . $today . "_" . $KeyArea . "_" . $Fraccion . ".png"); } if ($all == true && $KeyArea == false && $CurrentMonth == false) { // AllYear $Test->drawTitle(220, 22, "Toneladas {$CurrentYear}", 50, 50, 50, 585); $Test->Render("../../app/webroot/img/thumbs/graph_" . $CurrentYear . "_" . $KeyArea . ".png"); } if ($all == true && $KeyArea > 0 && $CurrentMonth == false) { // AllYearArea $Test->drawTitle(220, 22, "Toneladas {$ThisArea[$KeyArea]} {$CurrentYear}", 50, 50, 50, 585); $Test->Render("../../app/webroot/img/thumbs/graph_" . $CurrentYear . "_" . $KeyArea . ".png"); } // $Test->drawTitle(220,22,"Toneladas $MyMonth $CurrentYear",50,50,50,585); // $Test->Render("../../app/webroot/img/thumbs/graph_".$today."_".$KeyArea."_".$Fraccion.".png"); }
$DataSet->SetSerieName("Amount of Fuel Used","Serie1"); $DataSet->SetSerieName("Web Hits","Serie2"); */ $DataSet->AddPoint(array(10, 9.4, 7.7, 5, 1.7, 11, 13, 11, 13, 11.2, 13.6, 6.5), "Serie1"); $DataSet->AddPoint(array(3.4, 6.4, 8.6, 9.800000000000001, 9.9, 9.4, 7.7, 13, 11, 13.6, 11.2, 5.6), "Serie2"); $DataSet->AddPoint(array(7.1, 9.1, 10, 9.699999999999999, 8.199999999999999, 10, 7.7, 9.9, 9.800000000000001, 6.4, 11.6, 15.6), "Serie3"); $DataSet->AddPoint(array("Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"), "Serie4"); //$DataSet->AddAllSeries(); $DataSet->AddSerie("Serie1"); $DataSet->AddSerie("Serie2"); $DataSet->AddSerie("Serie3"); $DataSet->SetAbsciseLabelSerie("Serie4"); $DataSet->SetSerieName("Charcoal", "Serie1"); $DataSet->SetSerieName("Firewood", "Serie2"); $DataSet->SetSerieName("Kerosene", "Serie3"); $DataSet->SetYAxisName("Amount Used (kg)"); $DataSet->SetXAxisName("Month of the year"); // Initialise the graph $Test = new pChart(660, 230); $Test->drawGraphAreaGradient(90, 90, 90, 90, TARGET_BACKGROUND); // Prepare the graph area $Test->setFontProperties("fonts/tahoma.ttf", 8); $Test->setGraphArea(60, 40, 595, 190); // Initialise graph area $Test->setFontProperties("../Fonts/tahoma.ttf", 8); // Draw the SourceForge Rank graph $DataSet->SetYAxisName("Amount of Fuel Used"); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 213, 217, 221, TRUE, 0, 0); $Test->drawGraphAreaGradient(40, 40, 40, -50); $Test->drawGrid(4, TRUE, 230, 230, 230, 10); $Test->setShadowProperties(3, 3, 0, 0, 0, 30, 4); $Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription());
*/ // Standard inclusions include "../../pChart/pChart/pData.class"; include "../../pChart/pChart/pChart.class"; $array_to_display = $_SESSION['histo_tps_pannes_array']; //$array_to_display = round($array_to_display); $name_to_display = $_SESSION['histo_tps_pannes_nom']; $machine_to_display = $_SESSION['machine_nom']; // Dataset definition $DataSet = new pData(); $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
/** * This method return a graph containing information about evaluations * inside courses in sessions, it's used inside get_block method for * showing it inside dashboard interface * @return string img html */ public function get_evaluations_courses_in_sessions_graph() { $graphs = array(); if (!empty($this->sessions)) { $session_ids = array_keys($this->sessions); foreach ($session_ids as $session_id) { $courses_code = array_keys(Tracking::get_courses_list_from_session($session_id)); $courses_graph = array(); foreach ($courses_code as $course_code) { $cats = Category::load(null, null, $course_code, null, null, $session_id); if (isset($cats) && isset($cats[0])) { $alleval = $cats[0]->get_evaluations(null, true, $course_code); $alllinks = $cats[0]->get_links(null, true); $users = get_all_users($alleval, $alllinks); $datagen = new FlatViewDataGenerator ($users, $alleval, $alllinks); $evaluation_sumary = $datagen->get_evaluation_sumary_results(); if (!empty($evaluation_sumary)) { $items = array_keys($evaluation_sumary); $max = $min = $avg = array(); foreach ($evaluation_sumary as $evaluation) { $max[] = $evaluation['max']; $min[] = $evaluation['min']; $avg[] = $evaluation['avg']; } // Dataset definition $data_set = new pData; $data_set->AddPoint($max, "Max"); $data_set->AddPoint($avg, "Avg"); $data_set->AddPoint($min, "Min"); $data_set->AddPoint($items, "Items"); $data_set->SetXAxisName(get_lang('EvaluationName')); $data_set->SetYAxisName(get_lang('Percentage')); $data_set->AddAllSeries(); $data_set->RemoveSerie("Items"); $data_set->SetAbsciseLabelSerie("Items"); $graph_id = $this->user_id.'StudentEvaluationGraph'; $cache = new pCache(); // the graph id $data = $data_set->GetData(); if ($cache->IsInCache($graph_id, $data)) { //if we already created the img $img_file = $cache->GetHash($graph_id, $data); } else { // Initialise the graph $angle = -30; $test = new pChart($this->bg_width, $this->bg_height); $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 8); $test->fixHeightByRotation( $data_set->GetData(), $data_set->GetDataDescription(), $angle ); $test->setGraphArea(50, 30, $this->bg_width - 75, $this->bg_height - 75); $test->drawFilledRoundedRectangle( 7, 7, $this->bg_width - 20, $test->YSize - 20, 5, 240, 240, 240 ); $test->drawRoundedRectangle( 5, 5, $this->bg_width - 18, $test->YSize - 18, 5, 230, 230, 230 ); $test->drawGraphArea(255,255,255,TRUE); $test->setFixedScale(0,100,5); $test->drawScale( $data_set->GetData(), $data_set->GetDataDescription(), SCALE_ADDALL, 150, 150, 150, TRUE, $angle, 2, TRUE ); $test->setColorPalette(0,105,221,34); $test->setColorPalette(1,255,135,30); $test->setColorPalette(2,255,0,0); $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->drawOverlayBarGraph($data_set->GetData(),$data_set->GetDataDescription(), 100); // Finish the graph $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8); $test->drawLegend($this->bg_width-80,20,$data_set->GetDataDescription(),255,255,255); $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',10); $test->setColorPalette(0,50,50,50); $test->setColorPalette(1,50,50,50); $test->setColorPalette(2,50,50,50); $test->writeValues($data_set->GetData(),$data_set->GetDataDescription(),array("Min", "Max", "Avg")); $cache->WriteToCache($graph_id, $data_set->GetData(), $test); ob_start(); $test->Stroke(); ob_end_clean(); $img_file = $cache->GetHash($graph_id, $data_set->GetData()); } if (!empty($img_file)) { $courses_graph[$course_code] = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">'; } } } } if (!empty($courses_graph)) { $graphs[$session_id] = $courses_graph; } } } return $graphs; }
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())); }
protected function pChart($filename) { $pData = new pData(); $count = 1; # Give it a minute and a half @set_time_limit(30); $this->setFontSize(8); if (!$this->data || count($this->data) == 0) { return; } $pData->AddPoint($this->data, 'dataset'); $pData->AddPoint($this->labels, 'labels'); $pData->AddAllSeries(); $pData->SetAbsciseLabelSerie('labels'); $pData->SetYAxisName($this->y_title); $pData->SetXAxisName($this->x_title); # Set the file name: if ($filename == '') { $filename = md5(implode('', $this->data)); } # Create a "frame" $this->pChart->drawBackground(255, 255, 255); $this->pChart->drawFilledRoundedRectangle(0, 0, $this->x, $this->y, 5, 255, 255, 255); $this->pChart->drawRoundedRectangle(5, 5, $this->x - 5, $this->y - 5, 5, 230, 230, 230); if ($this->type == 'pie') { $this->pChart->loadColorPalette('tones-1.txt'); $this->pChart->drawBasicPieGraph($pData->GetData(), $pData->GetDataDescription(), 200, 200, 120, PIE_PERCENTAGE); $this->pChart->drawPieLegend($this->x - 150, 30, $pData->GetData(), $pData->GetDataDescription(), 250, 250, 250); } elseif ($this->type == 'pie3d') { $this->pChart->loadColorPalette('tones-1.txt'); $this->pChart->drawPieGraph($pData->GetData(), $pData->GetDataDescription(), 200, 200, 120, PIE_PERCENTAGE, true); $this->pChart->drawPieLegend($this->x - 150, 30, $pData->GetData(), $pData->GetDataDescription(), 250, 250, 250); } elseif ($this->type == 'line') { $this->pChart->setGraphArea(90, 30, $this->x - 30, $this->y - 50); $this->pChart->drawScale($pData->GetData(), $pData->GetDataDescription(), SCALE_NORMAL, 0, 0, 0, true); $this->pChart->drawTreshold(0, 143, 55, 72, TRUE, TRUE); $this->pChart->drawGrid(4, TRUE); //$this->pChart->drawLegend(90,35,$pData->GetDataDescription(),255,255,255); //$this->pChart->drawFilledLineGraph($pData->GetData(), $pData->GetDataDescription(), 20, true); //$this->pChart->drawCubicCurve($pData->GetData(), $pData->GetDataDescription()); //$this->pChart->drawLimitsGraph($pData->GetData(), $pData->GetDataDescription()); $this->pChart->drawFilledCubicCurve($pData->GetData(), $pData->GetDataDescription(), 0.01, 20, true); $this->pChart->drawPlotGraph($pData->GetData(), $pData->GetDataDescription(), 3, 2); $this->pChart->drawTreshold(0, 143, 55, 72, TRUE, TRUE); } elseif ($this->type = 'bar') { $this->pChart->drawBarGraph($pData->GetData(), $pData->GetDataDescription(), TRUE); } $this->setFontSize(11); $w = strlen($this->chart_title) * 1.5; @$this->pChart->drawTitle(0, 23, $this->chart_title, 0, 0, 0, $this->x); //$this->pCache->WriteToCache($filename,$pData->GetData(),$this->pChart); $this->pChart->Render(SITE_ROOT . '/core/cache/' . $filename . '.png'); echo '<img src="' . SITE_URL . '/core/cache/' . $filename . '.png" />'; }