0

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();
cronos
  • 536
  • 2
  • 8
  • 20

1 Answers1

1

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;
    }
miken32
  • 42,008
  • 16
  • 111
  • 154
  • I tried a lot of different things but no positive results :( – cronos Nov 01 '15 at 12:43
  • 1
    You changed it to match as above in my edit? It's a pretty clear programming error. Perhaps there are others in the code. – miken32 Nov 01 '15 at 15:18
  • Great; I didn't notice that error; not it works perfectly! – cronos Nov 01 '15 at 18:07
  • Glad to hear. You may want to post it on github as an issue, or I guarantee in 4 years you'll update the library and have this same problem again! – miken32 Nov 01 '15 at 18:21