Barplot with only negative values / SetYBase does not work as expected

74 views
Skip to first unread message

Larissa Werner

unread,
Mar 2, 2016, 7:52:11 AM3/2/16
to JpGraph
Hi
Y-Start should be less than 0 - How is this possible?
Thanx Gerhard

<?
define ("JPGPATH","/www/htdocs/jpgraph-3.5/src");
include_once (JPGPATH."/jpgraph.php");
include_once (JPGPATH."/jpgraph_bar.php");

// Data
$xdata = array("2016-05","2016-06","2016-07","2016-08","2016-09");
$ydata = array(-31,-35,-40,-32,-42);

// Description
$title = "Test";
$yunit="db";
$legend=sprintf("%s [%s]","Input Return",$yunit);

// Setup the graph.
$graph = new Graph(900,400,"auto");   
$graph->img->SetMargin(60,50,100,70);
$graph->SetShadow();

$miny= min($ydata);
$maxy= max($ydata);

$title.= sprintf(" Min: %5.1f  Max: %5.1f", $miny, $maxy);

  $graph->SetMarginColor("gray7");
  $graph->SetScale("textlin");
#  $graph->SetScale("textlin",-45,-10);
  $graph->xaxis->SetLabelSide(SIDE_UP);
  $graph->xaxis->SetTickSide(SIDE_DOWN);
  $graph->xaxis->SetLabelAlign('center','bottom');
  $graph->xaxis->SetTitlemargin(-35);

// Setup font for axis
$graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,8);
$graph->yaxis->SetFont(FF_VERDANA,FS_NORMAL,8);


$bplot = new BarPlot($ydata);
$bplot->SetWidth(0.3);
$graph->xaxis->SetPos('max');
#$graph->xaxis->SetPos(-10);
#$graph->yaxis->scale->SetAutoMin(-10);
#$graph->yaxis->scale->SetAutoMax(-10);
$bplot->SetYBase(-8);
$bplot->SetFillColor(array('red','blue','green'));

$bplot->SetLegend($legend);
$graph->legend->SetPos(0.05,0.87,'right','center');

$graph->Add($bplot);

// Set up the title for the graph
$graph->title->Set($title);

# Y Achsen Beschriftung
$graph->yaxis->SetTitle($yunit);
$graph->yaxis->SetTitleMargin(40);

// Setup X-axis title (color & font)
$graph->xaxis->SetTitle("Week",'high');

$graph->xaxis->title->SetColor("black");
$graph->xaxis->SetTickLabels($xdata);
$graph->xaxis->SetTextTickInterval(1);

// Finally send the graph to the browser
$graph->Stroke();
?>

test_mean.png
Reply all
Reply to author
Forward
0 new messages