如何使用Phpgraphlib将标题更改为位于图表的右上角?

时间:2015-10-26 21:56:28

标签: php phpgraphlib

我可以使用以下命令轻松找到位于中心或左侧的标题:

$graph->setTitleLocation("center");
$graph->setTitleLocation("left");

...但如果我使用它:

$graph->setTitleLocation("right");

我甚至不再看到图表了。完整代码:

<?php
include('../phpgraphlib.php');
$graph = new PHPGraphLib(500, 350);
$data = array(12124, 5535, 43373, 22223, 90432, 23332, 15544, 24523, 32778, 38878, 28787, 33243, 34832, 32302);
$graph->addData($data);
$graph->setTitle('Widgets Produced');
$graph->setTitleLocation("right");
$graph->setGradient('red', 'maroon');
$graph->createGraph();

1 个答案:

答案 0 :(得分:1)

This may be an error in the code。对于左侧和中间,他使用局部变量,但是对于右侧,他使用的是不存在的属性。

protected function generateTitle() 
{
    //spacing may have changed since earlier
    //use top margin or grid top y, whichever less
    $highestElement = ($this->top_margin < $this->y_axis_y2) ? $this->top_margin : $this->y_axis_y2;
    $textVertPos = ($highestElement / 2) - (self::TITLE_CHAR_HEIGHT / 2); //centered
    $titleLength = strlen($this->title_text);
    if ($this->bool_title_center) {
        $title_x = ($this->width / 2) - (($titleLength * self::TITLE_CHAR_WIDTH) / 2);
        $title_y = $textVertPos;
    } elseif ($this->bool_title_left) {
        $title_x = $this->y_axis_x1;
        $title_y = $textVertPos;
    } elseif ($this->bool_title_right) {
        $this->title_x = $this->x_axis_x2 - ($titleLength * self::TITLE_CHAR_WIDTH);
        $this->title_y = $textVertPos;
    }
    imagestring($this->image, 2, $title_x , $title_y , $this->title_text,  $this->title_color);
}

尝试将本地副本上对$this->title_x$this->title_y的引用更改为$title_x$title_y,并查看其工作原理:

    } elseif ($this->bool_title_right) {
        $title_x = $this->x_axis_x2 - ($titleLength * self::TITLE_CHAR_WIDTH);
        $title_y = $textVertPos;
    }