I have a problem with PHP Graphing library at JPGraph.net . I have a really simple LinePlot() and if i add a legend to the graph the bottom margin of the graph extend by circa 10 pixels. Making the graph legend Show() or Hide() doesn't make any difference the bottom margin is added to the graph right after the legend is associated with a lineplot.
Is there any solution to switch off this behaviour? Because i generate thumbnail size graphs (eg. 180x100) the bottom margin white area is quite "large".
For better understanding:
Left: starting point before legend is added
Right: After the legend is added, no other 开发者_如何学JAVAchanges to the margins/code of the graph
Oops i dont have enough reputation to post images :(
left_good right_bad
The solution for this problem is add:
$graph->graph_theme=null;
just before the:
$graph->Stroke();
Good Luck!
Keep in mind the legend is more or less independent from the graph itself, it can be placed anywhere.
The margin of the graph itself can - in most cases - be modified using...
Graph::SetMargin($left_m, $right_m, $top_m, $bottom_m)
...(margin in pixels) which could look like this in your code:
$graph = new Graph(180,100);
$graph->SetMargin(10,20,30,40);
/* followed by alot more code for your graph until... */
$graph->Stroke();
I advise looking into the extensive documentation which is included in the JPGraph packages, the classes are well documented and they offer alot of examples how to work with it.
I can concur with Bjorn that $graph->SetMargin(lMargin,rMargin,tMargin,bMargin); is the way to go. However, on my line plot setting the bottom margin doesn't appear to have any effect. In know there is a footer, and like the legend, populating this -- or not -- also has no effect on the bottom margin. If you stumble on anything like this I'd be really grateful to know how you solve it.
Best of luck, C
This margin is set in jpgraph_legend.inc.php on line 35.
private $ybottom_margin = 8;
This value cannot be changed by a method, it's a hard-coded margin which you can only change there.
But you can add a new method to the legend class:
function SetYBottomMargin($aYMarg) {
$this->ybottom_margin = $aYMarg;
}
Call it like $graph->legend->SetYBottomMargin(0); to set the bottom margin to 0.
精彩评论