コード例 #1
4
ファイル: allelo.php プロジェクト: FigBug/GamenightEx
function drawChart($title, $DataSet, $names, $colors, $legend = false)
{
    // Initialise the graph
    $Chart = new pChart(1300, 750);
    $Chart->setFontProperties("Fonts/tahoma.ttf", 8);
    $Chart->setGraphArea(50, 25, 1200, 725);
    $Chart->drawGraphArea(255, 255, 255, TRUE);
    $Chart->drawXYScale($DataSet->GetData(), $DataSet->GetDataDescription(), "ally", "allx", 150, 150, 150, TRUE, 45);
    $Chart->setLineStyle(4);
    // Draw the 0 line
    $Chart->setFontProperties("Fonts/tahoma.ttf", 6);
    $Chart->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
    foreach ($colors as $idx => $color) {
        $Chart->setColorPalette($idx, $color[0], $color[1], $color[2]);
    }
    $i = 0;
    foreach ($names as $name) {
        $Chart->drawXYGraph($DataSet->GetData(), $DataSet->GetDataDescription(), $name . "y", $name . "x", $i);
        $i++;
    }
    if ($legend) {
        $Chart->drawLegend(465, 40, $DataSet->GetDataDescription(), 255, 255, 255);
    }
    // Finish the graph
    $Chart->setFontProperties("Fonts/tahoma.ttf", 10);
    //  $Chart->drawTitle(60,22,$title,50,50,50,530);
    $Chart->Stroke();
}
コード例 #2
1
ファイル: plot.php プロジェクト: omusico/isle-web-framework
 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;
 }
コード例 #3
0
ファイル: pChartTest.php プロジェクト: rbraband/pChart
 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()));
 }
コード例 #4
0
$Test->setFontPropertiesDir("{$pChart_dir}/Fonts");
// Add an image
$Test->drawFromPNG($background, 0, 0);
$Test->reportWarnings("GD");
$Test->setFixedScale($min_y_value, $max_y_value, 5);
$Test->setFontProperties("{$pChart_dir}/Fonts/tahoma.ttf", 14);
$Test->setGraphArea($area_margin_left, 20, $width - 30, $height - 55);
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 255, 255, 255, TRUE, 0, 2, TRUE, 1);
$Test->drawGrid(4, TRUE, 233, 218, 213, 0);
//画网格
// Draw the area
$Test->drawArea($DataSet->GetData(), "Serie3", "Serie4", 239, 238, 227, 40);
$DataSet->RemoveSerie("Serie4");
// Draw the line graph
$Test->setColorPalette(0, 255, 237, 237);
$Test->setLineStyle(2, 0);
//设置虚线的宽度
$Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
$Test->setColorPalette(0, 243, 247, 252);
$Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 5, 3, 255, 255, 255);
// $Test->setFontProperties("{$pChart_dir}/Fonts/simfang.ttf",14);
$Test->writeValues($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie3");
// $Test->Render("example15.png");
$Test->Stroke();
function dump($data)
{
    echo "<pre>";
    print_r($data);
    echo "</pre>";
    exit;
}
コード例 #5
0
ファイル: Example15.php プロジェクト: han905/pChart-php5
$Test->setGraphArea(65, 30, 570, 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, 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);
// Draw the area
$DataSet->RemoveSerie("Serie4");
$Test->drawArea($DataSet->GetData(), "Serie1", "Serie2", 239, 238, 227, 50);
$DataSet->RemoveSerie("Serie3");
$Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
// Draw the line graph
$Test->setLineStyle(1, 6);
$DataSet->RemoveAllSeries();
$DataSet->AddSerie("Serie3");
$Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 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(), 255, 255, 255);
$Test->setFontProperties("../Fonts/tahoma.ttf", 10);
$Test->drawTitle(60, 22, "example 15", 50, 50, 50, 585);
// Add an image
$Test->drawFromPNG("../Sample/logo.png", 584, 35);
// Render the chart
コード例 #6
0
ファイル: schedule_cron.php プロジェクト: kostya1017/our
 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);
     }
 }
コード例 #7
0
$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);
$Test->drawLine(51, -2, 51, 402, 0, 0, 0);
$Test->setLineStyle(1);
$Test->drawTextBox(0, 0, 50, 400, $Title, 90, 255, 255, 255, ALIGN_BOTTOM_CENTER, TRUE, 0, 0, 0, 30);
$Test->setFontProperties("Fonts/pf_arma_five.ttf", 6);
// Draw the bar graph
$Test->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 70);
// Second chart
$DataSet->SetXAxisName("");
$Test->clearScale();
$Test->setGraphArea(110, 20, 350, 140);
$Test->drawGraphArea(213, 217, 221, FALSE);
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 213, 217, 221, TRUE, 0, 2);
$Test->drawGraphAreaGradient(40, 40, 40, -50);
$Test->drawGrid(4, TRUE, 230, 230, 230, 5);
// Draw the line chart
コード例 #8
0
/**
 * This function draw the graphic to be displayed on the user view as an image
 *
 * @param array $sql_result
 * @param string $start_date
 * @param string $end_date
 * @param string $type
 * @author Jorge Frisancho Jibaja
 * @version OCT-22- 2010
 * @return string
 */
function grapher($sql_result, $start_date, $end_date, $type = "") {
    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';

    if (empty($start_date)) { $start_date =""; }
    if (empty($end_date)) { $end_date =""; }
    if ($type == ""){ $type = 'day'; }
    $main_year  = $main_month_year = $main_day = array();
    // get last 8 days/months
    $last_days      = 5;
    $last_months    = 3;
    for ($i = $last_days; $i >= 0; $i--) {
        $main_day[date ('d-m-Y', mktime () - $i * 3600 * 24)] = 0;
    }
    for ($i = $last_months; $i >= 0; $i--) {
        $main_month_year[date ('m-Y', mktime () - $i * 30 * 3600 * 24)] = 0;
    }

    $i = 0;
    if (is_array($sql_result) && count($sql_result) > 0) {
        foreach ($sql_result as $key => $data) {
            //creating the main array
            $main_month_year[date('m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
            $main_day[date('d-m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
            if ($i > 500) {
                break;
            }
            $i++;
        }

        switch ($type) {
            case 'day':
                $main_date = $main_day;
                break;
            case 'month':
                $main_date = $main_month_year;
                break;
            case 'year':
                $main_date = $main_year;
                break;
        }

        // the nice graphics :D
        $labels = array_keys($main_date);
        if (count($main_date) == 1) {
            $labels = $labels[0];
            $main_date = $main_date[$labels];
        }

        $data_set = new pData();
        $data_set->AddPoint($main_date, 'Q');
        if (count($main_date)!= 1) {
            $data_set->AddPoint($labels, 'Date');
        }
        $data_set->AddAllSeries();
        $data_set->RemoveSerie('Date');
        $data_set->SetAbsciseLabelSerie('Date');
        $data_set->SetYAxisName(get_lang('Minutes', ''));
        $graph_id = api_get_user_id().'AccessDetails'.api_get_course_id().$start_date.$end_date.$type;
        $data_set->AddAllSeries();

        $cache = new pCache();
        // the graph id
        $data = $data_set->GetData();

        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 {
            // if the image does not exist in the archive/ folder
            // Initialise the graph
            $test = new pChart(760, 230);

            //which schema of color will be used
            $quant_resources = count($data[0]) - 1;
            // Adding the color schemma
            $test->loadColorPalette(api_get_path(LIBRARY_PATH).'pchart/palette/default.txt');

            $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/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($data_set->GetData(), $data_set->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 0, 0);
            $test->drawGrid(4, TRUE, 230, 230, 230, 50);
            $test->setLineStyle(2);
            // Draw the 0 line
            $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 6);
            $test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);

            if (count($main_date) == 1) {
                //Draw a graph
                echo '<strong>'.$labels.'</strong><br/>';
                $test->drawBarGraph($data_set->GetData(), $data_set->GetDataDescription(), TRUE);
            } else {
                //Draw the line graph
                $test->drawLineGraph($data_set->GetData(), $data_set->GetDataDescription());
                $test->drawPlotGraph($data_set->GetData(), $data_set->GetDataDescription(), 3, 2, 255, 255, 255);
            }

            // Finish the graph
            $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 8);
            $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 10);
            $test->drawTitle(60, 22, get_lang('AccessDetails'), 50, 50, 50, 585);

            //------------------
            //echo 'not in cache';
            $cache->WriteToCache($graph_id, $data_set->GetData(), $test);
            ob_start();
            $test->Stroke();
            ob_end_clean();
            $img_file = $cache->GetHash($graph_id, $data_set->GetData());
        }
        $foo_img = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">';
        return $foo_img;
    } else {
        $foo_img = api_convert_encoding('<div id="messages" class="warning-message">'.get_lang('GraphicNotAvailable').'</div>','UTF-8');
        return $foo_img;
    }

}
コード例 #9
0
ファイル: multia.php プロジェクト: cdkisa/majordomo
}
//---------------------------- drawScale
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), $scale, 80, 80, 80, TRUE, 0, 2);
//---------------------------- Grid
if ($_GET['grid'] == '0') {
    //
} else {
    $Test->drawGrid(1, TRUE, 230, 230, 230, 50);
}
//---------------------------- Set linestyle
if ($_GET['line']) {
    $line = $_GET['line'];
} else {
    $line = 1;
}
$Test->setLineStyle($line, 0);
//---------------------------- Set pointsstyle
if ($_GET['point']) {
    $point = $_GET['point'];
} else {
    $point = 1;
}
//---------------------------- Set custom RGB colors of channels 1-9
if ($p != '' && $c1r != 0) {
    $Test->setColorPalette(0, $c1r, $c1g, $c1b);
}
if ($p2 != '' && $c2r != 0) {
    $Test->setColorPalette(1, $c2r, $c2g, $c2b);
}
if ($p3 != '' && $c3r != 0) {
    $Test->setColorPalette(2, $c3r, $c3g, $c3b);