Any php graph framework that can output a .png with transparent plot background? [closed]

StackOverflow https://stackoverflow.com/questions/13082613

  •  14-07-2021
  •  | 
  •  

Question

As an example making an line graph, with a transparent background behind the plot...

preferably with anti aliased lines...

This way the generated .png graphs can be more useful and easier to blend in with other content etc....

I know php gd etc can output transparent background images... that's not exactly what I'm asking for here: the closest I've come is using jpgraph for php, and then taking the image output back to php gd and making the white background transparent and outputting that as a .png image with alpha background. its really ugly though, due to the fact that the grpah lines will have been anti aliased ontop of a white background, make those lines still have traces of white/(whatever color residue from the lines), and php gd etc isn't exactly providing the tools of photoshop to mask out and feather dirty pixels.

So far I've found nothing.. all of them just seem to want to default to white backgrounds or otherwise specified colors/background images. nothing with alpha channels. I just don't have the time or knowledge to make an entire library for making graphs

Was it helpful?

Solution

You can use fusion charts which provide this functionality to provide transparent background of generated graphs by setting bgAlpha='0' like this

<chart bgColor='999999,FFFFFF' bgAlpha='0' ...>

Also, you can use their documentation for more customizations.

You can also use Dojo Charts (Free) by setting following parameter

programmersChart.surface.rawNode.childNodes[1].setAttribute('fill-opacity','0');

OTHER TIPS

You can use ezcGraph for that.

The Graph component enables you to create line, pie and bar charts. The output driver mechanism allows you to create different image types from each chart, and the available renderers make the chart output customizable from simple two-dimensional charts to beautiful three-dimensional data projections.

From their tutorial page:

Each undefined color will default to a transparent white. As you can see in the example definition, you can define alpha values beside the normal RGB values for the colors.

One of the examples goes like this:

require_once 'tutorial_autoload.php';
require_once 'tutorial_custom_palette_palette.php';
$wikidata = include 'tutorial_wikipedia_data.php';
$graph = new ezcGraphBarChart();
$graph->palette = new tutorialCustomPalette();
$graph->title = 'Wikipedia articles';
// Add data
foreach ( $wikidata as $language => $data )
{
$graph->data[$language] = new ezcGraphArrayDataSet( $data );
}
$graph->data['German']->displayType = ezcGraph::LINE;
$graph->options->fillLines = 210;
$graph->render( 400, 150, 'tutorial_custom_palette.svg' ); 

and will result in an image like

Transparent Bar Chart

If you change the background color of this page, you will see the image is transparent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top