?
Solved

php jpgraph

Posted on 2014-04-30
5
Medium Priority
?
829 Views
Last Modified: 2014-05-01
I want to move the y-axis line over as the numbers overlap with the y-axis title. It's been a long time since I worked with jpgraph and found little or no documentation on moving just the line so larger numbers don't overlap the title.

Here is some example code I am using to play around with the position of the graph. See attached image.

<?php

require_once ('jpgraph/src/jpgraph.php');
require_once ('jpgraph/src/jpgraph_line.php');

$ydata = array(11,3,598,412,5,901,9,13,5,7);
$y2data = array(354,200,265,99,111,91,198,225,293,251);

// Create the graph and specify the scale for both Y-axis
$graph = new Graph(600,400,'auto');
$graph->SetScale('textlin');
$graph->SetY2Scale('lin');
$graph->SetShadow();
 
// Adjust the margin
$graph->img->SetMargin(80,140,20,40);
 
// Create the two linear plot
$lineplot=new LinePlot($ydata);
$lineplot2=new LinePlot($y2data);
 
// Add the plot to the graph
$graph->Add($lineplot);
$graph->AddY2($lineplot2);
$lineplot2->SetColor('orange');
$lineplot2->SetWeight(2);

// Adjust the axis color
$graph->y2axis->SetColor('orange');
$graph->yaxis->SetColor('blue');

$graph->yaxis->scale->ticks->Set(20, 20);

$graph->title->Set('Example 6');
$graph->xaxis->title->Set('X-title');
$graph->yaxis->title->Set('Y-title');

$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD,12);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

// Set the colors for the plots
$lineplot->SetColor('blue');
$lineplot->SetWeight(2);
$lineplot2->SetColor('orange');
$lineplot2->SetWeight(2);

// Set the legends for the plots
$lineplot->SetLegend('Plot 1');
$lineplot2->SetLegend('Plot 2');

// Adjust the legend position
$graph->legend->Pos(0.05,0.5,'right','center');

      // Display the graph
      //$graph->Stroke();
      $gdImgHandler = $graph->Stroke(_IMG_HANDLER);
      $rand = date("U");
      $fileName = ".output/$rand.png";
      $graph->img->Stream($fileName);
      print "<img src=\"$fileName\"><br>";
?>

Open in new window

2014-04-30-12-43-45.png
0
Comment
Question by:Robert Saylor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:alextoft
ID: 40032673
Have you tried fiddling with SetMargin?

http://jpgraph.net/download/manuals/chunkhtml/ch14s02.html
0
 
LVL 7

Author Comment

by:Robert Saylor
ID: 40032842
Yep did that.
0
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 total points
ID: 40032911
You need to play with:
$graph->SetMargin(x,y,z,w);
$graph->yaxis->title->SetMargin(5);

http://jpgraph.net/download/manuals/chunkhtml/ch32.html

HTH,
Dan
0
 
LVL 7

Author Closing Comment

by:Robert Saylor
ID: 40034246
Thanks Dan! That was the trick. I though I tried that but guess not.
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40034325
You're welcome.
Glad I could help!
0

Featured Post

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question