Exemplo n.º 1
0
/*
 * This work is hereby released into the Public Domain.
 * To view a copy of the public domain dedication,
 * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
 * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
 *
 */
require_once "../../LinePlot.class.php";
$graph = new Graph(300, 200);
$graph->setAntiAliasing(TRUE);
$x = array(-4, -5, -2, -8, -3, 1, 4, 9, 5, 6, 2);
$plot = new LinePlot($x);
$plot->setStyle(LINE_DASHED);
$plot->setSpace(4, 4, 10, 0);
$plot->setPadding(25, 15, 10, 18);
$plot->setBackgroundGradient(new LinearGradient(new Color(230, 230, 230), new Color(255, 255, 255), 90));
$plot->setFilledArea(7, 9, new Red(25));
$plot->setFilledArea(1, 4, new Yellow(25));
$plot->setColor(new Color(0, 0, 150, 20));
$plot->grid->setColor(new VeryLightGray());
$plot->mark->setType(MARK_SQUARE);
$plot->mark->setSize(4);
$plot->mark->setFill(new VeryDarkGreen(30));
$plot->mark->border->show();
$plot->mark->border->setColor(new DarkBlue(60));
$plot->xAxis->label->hide(TRUE);
$plot->xAxis->setNumberByTick('minor', 'major', 3);
$plot->yAxis->setLabelNumber(8);
$plot->legend->add($plot, "My line");
$plot->legend->setPosition(0.9, 0.77);
$graph->add($plot);
Exemplo n.º 2
0
<?php

/*
 * This work is hereby released into the Public Domain.
 * To view a copy of the public domain dedication,
 * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
 * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
 *
 */
require_once "../../LinePlot.class.php";
$graph = new Graph(150, 100);
$graph->setAntiAliasing(TRUE);
$x = array(1, 2, 5, 0.5, 3, 8, 7, 6, 2, -4);
$plot = new LinePlot($x);
$plot->grid->setNobackground();
$plot->setPadding(20, 8, 8, 20);
$plot->setXAxisZero(FALSE);
// Set a background gradient
$plot->setBackgroundGradient(new LinearGradient(new Color(210, 210, 210), new Color(255, 255, 255), 0));
// Set semi-transparent background gradient
$plot->setFillGradient(new LinearGradient(new Color(230, 150, 150, 20), new Color(230, 230, 180, 50), 90));
$plot->xAxis->label->hideFirst(TRUE);
$plot->xAxis->label->hideLast(TRUE);
$plot->xAxis->setNumberByTick('minor', 'major', 2);
$graph->add($plot);
$graph->draw();
$graph->setAntiAliasing(TRUE);
$graph->title->set("It is a title");
$graph->title->setBackgroundColor(new Color(255, 255, 255, 25));
$graph->title->border->show();
$graph->title->setPadding(3, 3, 3, 3);
$label = label("Artichow", new Font5());
$graph->addLabel($label, 0.5, 0.5);
$label = label("Current timestamp: " . date("Y-m-d H:i:s") . "", new Font4());
$label->setAlign(LABEL_RIGHT, LABEL_TOP);
$graph->addAbsLabel($label, new Point(395, 395));
$x = array();
for ($i = 0; $i < 6; $i++) {
    $x[] = mt_rand(-100, 100);
}
$plot = new LinePlot($x);
$plot->setBackgroundGradient(new LinearGradient(color(80), color(80), 0));
$plot->setColor(color());
$plot->setFillGradient(new LinearGradient(color(), color(), 90));
$plot->mark->setType(MARK_CIRCLE);
$plot->mark->setSize(40);
$plot->mark->border->show();
// All possible backgrounds
if (mt_rand(0, 2) === 0) {
    $plot->mark->setFill(new RadialGradient(color(20), color(30)));
} else {
    $plot->mark->setFill(new LinearGradient(color(20), color(30), 90 * mt_rand(0, 1)));
}
$plot->mark->border->setColor(new Color(0, 0, 0, 50));
$plot->yAxis->setLabelNumber(15);
$plot->yAxis->setLabelPrecision(1);
$plot->yAxis->setNumberByTick('minor', 'major', 4);
Exemplo n.º 4
0
/**
* Формирование графика.
*
* Функция формирует, а затем записывает в файл ($File) изображение графика по
* переданным пользователем данным($Lines). Данная функция может рисовать как одиночные,
* так и многолинейные графики.Исходными данными является массив, элементы которого также
* является массивами исходных данных для соответствующих графиков (данная структура
* сохраняется и для одиночных графиков!). Цвет каждой линии передается в массиве
* $Colors, ключи которого совпадают с ключами массива исходных данных. Цвет задается
* шестнадцатиричным кодом цвета (например, 0x000000 для черного цвета).
*
* @param string  <заголовок диаграммы>
* @param string  <полный путь с именем файла-результата>
* @param array   <исходные данные>
* @param array   <подписи к оси Ox>
* @param array   <цвета линий>
*/
function Artichow_Line($Name, $File, $Lines, $Labels, $Colors)
{
    #-----------------------------------------------------------------------------
    $Graph = new Graph(1000, 300);
    $Graph->setDriver('gd');
    $Graph->setAntiAliasing(TRUE);
    #-----------------------------------------------------------------------------
    $Graph->title->set($Name);
    $Graph->title->setFont(new Tuffy(15));
    $Graph->title->move(0, -5);
    #-----------------------------------------------------------------------------
    if (Count($Lines) > 1) {
        #---------------------------------------------------------------------------
        $Group = new PlotGroup();
        $Group->setPadding(40, 40);
        $Group->setBackgroundColor(new Color(240, 240, 240));
    }
    #-----------------------------------------------------------------------------
    $IsSetLabel = FALSE;
    #-----------------------------------------------------------------------------
    foreach ($Lines as $LineID => $Line) {
        #---------------------------------------------------------------------------
        $Plot = new LinePlot($Line);
        $Color = Color_RGB_Explode($Colors[$LineID]);
        $Plot->setColor(new Color($Color['R'], $Color['G'], $Color['B']));
        $Plot->setThickness(1);
        $Plot->setBackgroundGradient(new LinearGradient(new Color(240, 240, 240), new Color(255, 255, 255), 0));
        $Plot->setFillGradient(new LinearGradient(new LightOrange(10), new VeryLightOrange(90), 90));
        $Plot->setPadding(50, 50, 50, 50);
        #---------------------------------------------------------------------------
        $Plot->mark->setType(Mark::CIRCLE);
        $Plot->mark->setSize(5);
        #---------------------------------------------------------------------------
        $Plot->label->set($Line);
        $Plot->label->move(0, -15);
        $Plot->label->setBackgroundGradient(new LinearGradient(new Color(250, 250, 250, 10), new Color(255, 200, 200, 30), 0));
        $Plot->label->border->setColor(new Color(20, 20, 20, 20));
        $Plot->label->setPadding(2, 2, 2, 2);
        #---------------------------------------------------------------------------
        if (Count($Lines) < 2) {
            #-------------------------------------------------------------------------
            $Plot->xAxis->setLabelText($Labels);
            $Plot->yAxis->setLabelPrecision(1);
        } else {
            #-------------------------------------------------------------------------
            if (!$IsSetLabel) {
                #-----------------------------------------------------------------------
                $Plot->setXAxis(Plot::BOTTOM);
                $IsSetLabel = TRUE;
            }
        }
        #---------------------------------------------------------------------------
        if (Count($Lines) > 1) {
            $Group->add($Plot);
        }
        #---------------------------------------------------------------------------
        if (Count($Lines) > 1) {
            #-------------------------------------------------------------------------
            $Graph->add($Group);
            #-------------------------------------------------------------------------
            $Group->axis->bottom->setTickStyle(0);
            $Group->axis->bottom->setLabelText($Labels);
        } else {
            $Graph->add($Plot);
        }
    }
    #-----------------------------------------------------------------------------
    $Graph->draw($File);
    #-----------------------------------------------------------------------------
    return TRUE;
}
 */
require_once "../../LinePlot.class.php";
function color()
{
    return new Color(mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 100));
}
$width = mt_rand(200, 400);
$graph = new Graph($width, 400);
$graph->setAntiAliasing(TRUE);
$graph->setBackgroundColor(new Color(50, 50, 50));
$x = array(-100, 35, -20, 15, 79, -50);
$plot = new LinePlot($x);
$plot->setAbsSize($width - 20, 380);
$plot->setAbsPosition(mt_rand(0, 20), mt_rand(0, 20));
$plot->setThickness(mt_rand(2, 5));
$plot->setBackgroundGradient(new LinearGradient(color(), color(), mt_rand(0, 1) * 90));
$plot->yAxis->setLabelNumber(mt_rand(0, 10));
/*
$plot->setYMin(-80);
$plot->setYMax(120);
*/
$plot->xAxis->setLabelInterval(2);
$plot->xAxis->setTickInterval(2);
$major = $plot->xAxis->tick('major');
$major->setSize(10);
$minor = $plot->xAxis->tick('minor');
$minor->setSize(6);
$plot->xAxis->setNumberByTick('minor', 'major', 4);
$plot->xAxis->label->hideFirst(TRUE);
$plot->grid->setType(LINE_DOTTED);
$plot->label->set($x);