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); }
function prepareData($scaleX, $scaleY, $SQL, $scaleType) { global $conn; $DataSet = new pData(); $result = pg_query($conn, $SQL); if (!$result) { echo "An error occured.\n"; } while ($row = pg_fetch_row($result)) { $DataSet->AddPoint($row[1], "Serie2"); $DataSet->AddPoint(mktime(0, 0, 0, substr($row[0], 5, 2), substr($row[0], 8, 2), substr($row[0], 0, 4)), "Serie1"); } $DataSet->SetAbsciseLabelSerie("Serie1"); $DataSet->AddSerie("Serie2"); $DataSet->SetYAxisName($scaleY); $DataSet->SetXAxisFormat($scaleType); return $DataSet; }
$DataSet->AddPoint(array(700, 2705, 2041, 1712, 2051, 846, 903), "Serie2"); $DataSet->AddPoint(array("03 Oct", "02 Oct", "01 Oct", "30 Sep", "29 Sep", "28 Sep", "27 Sep"), "Serie3"); $DataSet->AddSerie("Serie1"); $DataSet->SetAbsciseLabelSerie("Serie3"); $DataSet->SetSerieName("SourceForge Rank", "Serie1"); $DataSet->SetSerieName("Web Hits", "Serie2"); // 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("Sourceforge Rank"); $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()); $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);
protected function _createVisitsGraph() { // load pChart graphic library $this->_loadLibs(); // définition des données à afficher $dataSet = new pData(); // need config, to know which data user wants to display : visits, unique visitors, pageviews $sefConfig = Sh404sefFactory::getConfig(); $dataTypeString = str_replace('ga:', '', $sefConfig->analyticsDashboardDataType); // get data from response $data = array(); $maxY = 0; foreach ($this->_rawData['visits'] as $entry) { $data[] = $entry->{$dataTypeString}; if ($entry->{$dataTypeString} > $maxY) { $maxY = $entry->{$dataTypeString}; } } // format dates $dates = Sh404sefHelperAnalytics::formatAbciseDates($this->_rawData['visits'], $this->_options); $dataSet->AddPoint($data, $dataTypeString); $dataSet->AddPoint($dates, "dates"); $dataSet->addSerie($dataTypeString); $dataSet->SetAbsciseLabelSerie("dates"); $label = JText::_('COM_SH404SEF_ANALYTICS_DATA_' . strtoupper($dataTypeString)); $dataSet->SetSerieName($label, $dataTypeString); // Initialise the graph $w = $this->_options['cpWidth']; $w = empty($w) ? 400 : intval($w - 40); $h = 225; $centreX = intval(0.5 * $w); $centreY = intval(0.5 * $h); $chart = new pChart($w, $h); $fontSize = 8; // calculate left margin based on max value to display $leftMargin = 20 + $fontSize + 20 + $fontSize * strlen($maxY); $bottomMargin = 5 + $fontSize * 6; switch ($this->_options['groupBy']) { case 'ga:year,ga:month,ga:week,ga:day': $YAxisName = JText::_('Day'); break; // date string represents a week number // date string represents a week number case 'ga:year,ga:month,ga:week': $YAxisName = JText::_('Week'); break; case 'ga:year,ga:month': $YAxisName = JText::_('Month'); break; } $dataSet->SetYAxisName($label . JText::_('COM_SH404SEF_ANALYTICS_REPORT_PER_LABEL') . $YAxisName); $chart->setFontProperties($this->_baseChartPath . DS . 'Fonts/arial.ttf', $fontSize); $chart->setGraphArea($leftMargin, 30, $w - 20, $h - $bottomMargin); $chart->drawFilledRoundedRectangle(7, 7, $w - 7, $h - 7, 5, 240, 240, 240); $chart->drawRoundedRectangle(5, 5, $w - 5, $h - 5, 5, 230, 230, 230); $chart->drawGraphArea(255, 255, 255, TRUE); $d = $dataSet->GetData(); if (!empty($d)) { $chart->drawScale($d, $dataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 60, 0, false); $chart->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the 0 line $chart->setFontProperties($this->_baseChartPath . DS . 'Fonts/arial.ttf', $fontSize); $chart->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Draw the line graph $chart->drawLineGraph($d, $dataSet->GetDataDescription()); $chart->drawPlotGraph($d, $dataSet->GetDataDescription(), 3, 2, 255, 255, 255); } // create a temporary file for $user =& JFactory::getUser(); // make sure the root tmp dir exists $rootDir = 'tmp' . DS . 'sh404sef_analytics'; Sh404sefHelperFiles::createDirAndIndex(JPATH_ROOT . DS . $rootDir); // file name is per user $basePath = $rootDir . DS . md5('useless_' . $user->id . '_hashing') . DS; // create path and make sure there's an index.html file in it Sh404sefHelperFiles::createDirAndIndex(JPATH_ROOT . DS . $basePath); $imageFileName = Sh404sefHelperAnalytics::createTempFile($basePath, $this->_options['report'] . '.' . $this->_options['accountId'] . '.visits.' . $dataTypeString); $chart->Render(JPATH_ROOT . DS . $imageFileName); // need cleaning up, so let's remove all report files for that user older than an hour or so Sh404sefHelperAnalytics::cleanReportsImageFiles(JPATH_ROOT . DS . $basePath, $age = 4000); return JURI::root() . $imageFileName; }
*/ // 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);
$data_count++; }); $performance = number_format(round(($points[count($points) - 1] / $points[0] - 1) * 100, 2), 2, ',', ''); // Dataset definition // File $FileName = './tmp/' . md5($user['name']) . ".png"; // Graph $DataSet = new pData(); $DataSet->AddPoint($points, "points"); $DataSet->AddPoint($rank, "rank"); $DataSet->AddPoint($time, "time"); $DataSet->AddSerie("points"); $DataSet->SetAbsciseLabelSerie(); $DataSet->SetSerieName("Punkte", "points"); $DataSet->SetSerieName("Rank", "rank"); $DataSet->SetYAxisName("Punkte"); $DataSet->SetAbsciseLabelSerie("time"); //$DataSet->SetXAxisFormat("date"); // Cache definition $Cache = new pCache('../charts/Cache/'); if ($use_cache && !$Cache->GetFromCache(md5($user['name']), $DataSet->GetData(), $FileName) or !$use_cache) { // Initialise the graph $Test = new pChart(715, 230); $Test->setDateFormat('d.m H:i'); $Test->setFontProperties("../charts/Fonts/tahoma.ttf", 8); $Test->setGraphArea(60, 30, 650, 150); $Test->drawFilledRoundedRectangle(7, 7, 708, 223, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 710, 225, 5, 163, 203, 167); $Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawGraphAreaGradient(163, 203, 167, 50); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_DIFF, 150, 150, 150, TRUE, 75, 0, FALSE, $skip_scale);
/** * 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; }
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"); }
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 "; $Test->setLineStyle(2);
/* Example1 : A simple line chart */ // Standard inclusions include "src/pData.php"; include "src/pChart.php"; // 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());
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"); }
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)));
<?php /* Example16 : Importing CSV data */ // Standard inclusions include "pChart/pData.class"; include "pChart/pChart.class"; // Dataset definition $DataSet = new pData(); $DataSet->ImportFromCSV("Sample/CO2.csv", ",", array(1, 2, 3, 4), TRUE, 0); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie(); $DataSet->SetYAxisName("CO2 concentrations"); // Initialise the graph $Test = new pChart(700, 230); $Test->reportWarnings("GD"); $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(60, 30, 680, 180); $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, 90, 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
$myarr1[$i] = $i; } // 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
Example17 : Playing with axis */ // Standard inclusions include "pChart/pData.class"; include "pChart/pChart.class"; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint(array(100, 320, 200, 10, 43), "Serie1"); $DataSet->AddPoint(array(23, 432, 43, 153, 234), "Serie2"); $DataSet->AddPoint(array(1217541600, 1217628000, 1217714400, 1217800800, 1217887200), "Serie3"); $DataSet->AddSerie("Serie1"); $DataSet->AddSerie("Serie2"); $DataSet->SetAbsciseLabelSerie("Serie3"); $DataSet->SetSerieName("Incoming", "Serie1"); $DataSet->SetSerieName("Outgoing", "Serie2"); $DataSet->SetYAxisName("Call duration"); $DataSet->SetYAxisFormat("time"); $DataSet->SetXAxisFormat("date"); // Initialise the graph $Test = new pChart(700, 230); $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
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); } }
// Standard inclusions include "../../pChart/pChart/pData.class"; include "../../pChart/pChart/pChart.class"; $array_to_display = $_SESSION['histo_downtime_array']; //$array_to_display = round($array_to_display); $name_to_display = $_SESSION['histo_downtime_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("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());
/** * 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); } }
Example23 : Playing with background bis */ // Standard inclusions include "../lib/pData.php"; include "../lib/pChart.php"; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint(array(9, 9, 9, 10, 10, 11, 12, 14, 16, 17, 18, 18, 19, 19, 18, 15, 12, 10, 9), "Serie1"); $DataSet->AddPoint(array(10, 11, 11, 12, 12, 13, 14, 15, 17, 19, 22, 24, 23, 23, 22, 20, 18, 16, 14), "Serie2"); $DataSet->AddPoint(array(4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), "Serie3"); $DataSet->AddAllSeries(); $DataSet->RemoveSerie("Serie3"); $DataSet->SetAbsciseLabelSerie("Serie3"); $DataSet->SetSerieName("January", "Serie1"); $DataSet->SetSerieName("February", "Serie2"); $DataSet->SetYAxisName("Temperature"); $DataSet->SetYAxisUnit("°C"); $DataSet->SetXAxisUnit("h"); // Initialise the graph $Test = new pChart(700, 230); $Test->drawGraphAreaGradient(132, 173, 131, 50, TARGET_BACKGROUND); $Test->setFontProperties("../Fonts/tahoma.ttf", 8); $Test->setGraphArea(120, 20, 675, 190); $Test->drawGraphArea(213, 217, 221, FALSE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALL, 213, 217, 221, TRUE, 0, 2, TRUE); $Test->drawGraphAreaGradient(163, 203, 167, 50); $Test->drawGrid(4, TRUE, 230, 230, 230, 20); // Draw the bar chart $Test->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 70); // Draw the title $Title = " Average Temperatures during\r\n the first months of 2008 ";
Example22 : Customizing plot graphs */ // Standard inclusions include "pChart/pData.class"; include "pChart/pChart.class"; // Dataset definition $DataSet = new pData(); $DataSet->AddPoint(array(60, 70, 90, 110, 100, 90), "Serie1"); $DataSet->AddPoint(array(40, 50, 60, 80, 70, 60), "Serie2"); $DataSet->AddPoint(array("Jan", "Feb", "Mar", "Apr", "May", "Jun"), "Serie3"); $DataSet->AddSerie("Serie1"); $DataSet->AddSerie("Serie2"); $DataSet->SetAbsciseLabelSerie("Serie3"); $DataSet->SetSerieName("Company A", "Serie1"); $DataSet->SetSerieName("Company B", "Serie2"); $DataSet->SetYAxisName("Product sales"); $DataSet->SetYAxisUnit("k"); $DataSet->SetSerieSymbol("Serie1", "Sample/Point_Asterisk.gif"); $DataSet->SetSerieSymbol("Serie2", "Sample/Point_Cd.gif"); // Initialise the graph $Test = new pChart(700, 230); $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(65, 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, TRUE); $Test->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the title $Test->setFontProperties("Fonts/pf_arma_five.ttf", 6); $Title = "Comparative product sales for company A & B ";
*/ // Standard inclusions include "pChart/pData.class"; include "pChart/pChart.class"; // Dataset definition $DataSet = new pData(); // Compute the points for ($i = 0; $i <= 360; $i = $i + 10) { $DataSet->AddPoint(cos($i * 3.14 / 180) * 80 + $i, "Serie1"); $DataSet->AddPoint(sin($i * 3.14 / 180) * 80 + $i, "Serie2"); } $DataSet->SetSerieName("Trigonometric function", "Serie1"); $DataSet->AddSerie("Serie1"); $DataSet->AddSerie("Serie2"); $DataSet->SetXAxisName("X Axis"); $DataSet->SetYAxisName("Y Axis"); // Initialise the graph $Test = new pChart(300, 300); $Test->drawGraphAreaGradient(0, 0, 0, -100, TARGET_BACKGROUND); // Prepare the graph area $Test->setFontProperties("Fonts/tahoma.ttf", 8); $Test->setGraphArea(55, 30, 270, 230); $Test->drawXYScale($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie1", "Serie2", 213, 217, 221, TRUE, 45); $Test->drawGraphArea(213, 217, 221, FALSE); $Test->drawGraphAreaGradient(30, 30, 30, -50); $Test->drawGrid(4, TRUE, 230, 230, 230, 20); // Draw the chart $Test->setShadowProperties(2, 2, 0, 0, 0, 60, 4); $Test->drawXYGraph($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie1", "Serie2", 0); $Test->clearShadow(); // Draw the title
$DataSet->SetAbsciseLabelSerie("Serie3"); $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);
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.'">'; } */ } }
} } //print_r($arrtotalamt); //print_r($p); //echo "?? $minquoteamtinmonth ???"; //die; $DataSet = new pData(); $DataSet->AddPoint(array($arrtotalamt[0], $arrtotalamt[1], $arrtotalamt[2], $arrtotalamt[3], $arrtotalamt[4], $arrtotalamt[5]), "Serie1"); $DataSet->AddPoint(array($minquoteamtinmonth, $minquoteamtinmonth, $minquoteamtinmonth, $minquoteamtinmonth, $minquoteamtinmonth, $minquoteamtinmonth), "Serie2"); $DataSet->AddPoint(array($p[0], $p[1], $p[2], $p[3], $p[4], $p[5]), "Serie3"); $DataSet->AddSerie("Serie1"); $DataSet->AddSerie("Serie2"); $DataSet->SetAbsciseLabelSerie("Serie3"); $DataSet->SetSerieName("Amount", "Serie1"); $DataSet->SetSerieName("Control ({$minquoteamtinmonth})", "Serie2"); $DataSet->SetYAxisName("Amount({$defcurrencycode})"); // $DataSet->SetYAxisUnit("RM"); $Test = new pChart(600, 230); $Test->setFontProperties("../simantz/class/pchart/Fonts/tahoma.ttf", 8); $Test->setGraphArea(65, 30, 550, 200); $Test->drawFilledRoundedRectangle(7, 7, 593, 223, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 595, 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); $Test->writeValues($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie1"); // Draw the title $Test->setFontProperties("../simantz/class/pchart/Fonts/pf_arma_five.ttf", 8); $Title = "QUotation Amount Vs Time For {$defaultorganization_name}"; $Test->drawTextBox(65, 10, 550, 25, $Title, 0, 255, 255, 255, ALIGN_CENTER, TRUE, 0, 0, 0, 30); // Draw the line graph
// 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 $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
/** * 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" />'; }