Kevin Orriss
Kevin Orriss

Reputation: 1032

JpGraph: LinePlot->SetWeight will not work

I am using JpGraph version 3.5.0b1 to create some graphs for a PDF document and I have hit a problem that has taken half of my day trying to work out whats going wrong.

All i want to do is change the line thickness of my lineplot but no matter what I try, it always defaults to 1 (assuming 1 is the default).

I have done my research and know that I have to set it after I add it to the graph and also that if antialias is set to true then SetWeight is ignored. My code follows these rules and yet still nothing. I am able to change the colour of the line so I know its nothing to do with how I'm calling the methods.

Can anyone help me here please? I would be hugely grateful as it is starting to annoy me just a tad.

Anyway, here is a little snippet of my code:

$lineplot = new LinePlot($ydata, $xdata);
$graph->Add($lineplot);
$lineplot->SetColor("red");
$lineplot->SetWeight(2);

Upvotes: 3

Views: 7690

Answers (4)

mtjmohr
mtjmohr

Reputation: 99

The issue for me here is that my registered JpGraph version 3.5.0b1 does not seem to work at all concerning the line weight and also for other display switches.

After downgrading to version 3.1.7p, everything worked fine independent of any anti-aliasing switches or the positioning of SetWeight after Add().

Thus, at the very moment, I can only recommend downgrading to a non-3.5.0b1 version.

Upvotes: 0

LWurm
LWurm

Reputation: 542

SetWeight() will do nothing until you turn off anti-aliasing. JpGraph mentions this in their manual in the using anti-aliasing page.

I tested this in version 3.5.0b1 and the following must be done:

// Ensure anti-aliasing is off. If it is not, you can SetWeight() all day and nothing will change.
$graph->img->SetAntiAliasing(false); 

// Create linear plot
$lineplot = new LinePlot($ydata, $xdata);

// Add plot to graph
$graph->Add($lineplot);

// Set line weight. This must be done AFTER adding the plot to the graph in version 3.5.0b1. I haven't verified this in other versions.
$lineplot->SetWeight(2); 

Upvotes: 12

sean
sean

Reputation: 59

I had similar problem, resolved by using $p1->SetStyle('solid') AFTER adding the lineplot to the graph:

    $p1 = new LinePlot($min_values);
    $graph->Add($p1);
    $p1->SetWeight(3); 
    $p1->SetColor("blue");
    $p1->SetLegend("Minimum Values");
    $p1->SetStyle("solid");

Here's a related link, validating Sean's recommendation to place the SetWeight and SetColor method calls AFTER calling the Add lineplot method.

Upvotes: 2

HDC Web team
HDC Web team

Reputation: 31

I ran into this same thing, seems to be a bug with 3.5 as far as I can tell. It's even ignored in the examples distributed with 3.5.

Falling back to 3.0.7 works for me, so try that if you don't need any 3.5-specific features.

Upvotes: 3

Related Questions