0

通过使用以下命令,我可以轻松地将标题定位在中心或左侧:

$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();
4

1 回答 1

1

这可能是代码中的错误。对于 left 和 center,他使用局部变量,但对于 right,他使用不存在的属性。

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;
    }
于 2015-10-28T22:00:01.027 回答