phpjpgraph

Transparent background in jpGraph


I'm trying to achieve a line graph with transparent background, but so far, I can only set the background to a specific color. Since it's PNG, it should be possible though.

$linePlot = new LinePlot($plotData);
$linePlot->SetFillColor('#61a9f3@.6');

$graph = new Graph(300, 100);
$graph->SetScale('intint');

$graph->SetAlphaBlending();
$graph->SetMarginColor('black:1');
$graph->SetFrame(true,'black', 0);

$graph->Add($linePlot);
$graph->Stroke();

Result

Graph doesn't have transparent background

Not transparent, but black


Solution

  • $graph->SetTheme($theme_class);
    $graph->img->SetAntiAliasing(false);
    $graph->title->Set('Filled Y-grid');
    $graph->SetMarginColor('White:0.6'); 
    $graph->SetFrame(true,'White:0.6',1); // The '1' here seems to be irrelevant
                                         // I've tried much larger numbers with no
                                         // change. This is supposed to be frame
                                         // width (in pixels). 
    $graph->SetBox(false);
    

    Reference: change margin color for a jpgraph