Changing the display settings of line/bar graphs

You should be careful when adding additional lines or bars to graphs and when changing color settings etc.

For example, in the previous version of JpGraph, after generating the 'BarPlot' instance and changing some settings, we used the Add() instance applied to $graph. But when using the theme class, this won't work. Because when Add() is called, all previous settings are ignored and the theme's defaults are used.

To avoid this, you should change each setting individually after using Add() when you want to customize. The following is sample code showing how to change colors in BarPlot.

1
2
3
4
5
6
7
8
9
10
<?php
$data1y=array(47,80,40,116);
$bplot = new BarPlot($data1y);
$graph->Add($bplot);
 
// you can change properties of the plot only after calling Add()
$bplot->SetWeight(0);
$bplot->SetFillGradient('#FFAAAA:0.7', '#FFAAAA:1.2', GRAD_VER);    
 
?>

If you use the code shown below, the changes made using the SetWeight() and SetFillGradient() method will be overwritten by Add() and won't be applied .

1
2
3
4
// this is an invalid example
$bplot->SetWeight(0);
$bplot->SetFillGradient('#FFAAAA:0.7', '#FFAAAA:1.2', GRAD_VER);    
$graph->Add($bplot);

PiePlot settings can be changed in the same way. For examples relating to BarPlot, please see 'new_bar1.php' on the gallery page.