Reputation: 568
I can easily locate the title to be at the center or to left by using these commands:
$graph->setTitleLocation("center");
$graph->setTitleLocation("left");
… but if I use this:
$graph->setTitleLocation("right");
I don’t even see the graph anymore. Full code:
<?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();
Upvotes: 0
Views: 92
Reputation: 42724
This may be an error in the code. For left and center, he uses a local variable, but for right he uses a property that doesn't exist.
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);
}
Try changing the references to $this->title_x
and $this->title_y
to $title_x
and $title_y
on your local copy, and see how that works:
} elseif ($this->bool_title_right) {
$title_x = $this->x_axis_x2 - ($titleLength * self::TITLE_CHAR_WIDTH);
$title_y = $textVertPos;
}
Upvotes: 1