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

これは、コードのエラーである可能性があります。左と中央にはローカル変数を使用していますが、右には存在しないプロパティを使用しています。

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 に答える