Thursday, 21 October 2010

jpGraph - cannot change line colour (or color)

Using jpGraph, an excellent package for plotting graphs from database data via PHP, I hit a problem: setting
$lineplot->Setcolor("blue"); 
had no result. Nor did
$lineplot->SetWeight(2);
Eventually, I sent off an enquiry to jpGraph - and back came a very prompt reply (from the Far East):


in version 3.5.0b1, methods to change designs of each plot should be used after $graph->add($plot) method.
This is really counter-intuitive. But it works.

So it goes like this

$bplot = new BarPlot($data1y);
$graph->Add($bplot);
 
// NOW change properties of the plot - these work ONLY after calling Add()
$bplot->SetWeight(0);
$bplot->SetFillGradient('#FFAAAA:0.7', '#FFAAAA:1.2', GRAD_VER);    
 


There is a note in the documentation included as part of the package, at:


jpgraph-3.5.0b1/docs/chunkhtml/ch29s02.html

7 comments:

Konstantin Galileyev said...

Thank you!

eyeman said...

Thank you. This really helped me out.

Thailandian said...

Thank you. I just wish I had found your very useful post much earlier!

I've bookmarked your blog on the strength of this, and will keep it in mind whenever I run into problems - thanks again.

Unknown said...

Thanks. Their included example files have it wrong, so this helped heaps :)

Unknown said...

Thank you, found a solution via google at stackoverflow and then here. Began doubting my own sanity.

Unknown said...

thanks :)

Unknown said...

Super helpful, many thanks