in reply to Re: doughnut charts with gd:graph
in thread doughnut charts with gd:graph

You already have the image as a pie so why not just overlay a background-coloured circle on the middle?

I can draw a circle separately. Here's the separate code. I use GD::Simple

#!/usr/bin/perl use CGI ':standard'; use strict; use warnings; use GD::Simple; # create a new image (width, height) my $img = GD::Simple->new(200, 100); $img->bgcolor('white'); $img->fgcolor('blue'); $img->moveTo(60, 50); # (x, y) $img->ellipse(80, 80); binmode STDOUT; print "Content-type: image/png\n\n"; print $img->png;

How can I insert it to the Pie chart code... Can you help me?

Can I use like this?

my $img = (GD::Simple->new(200, 100), GD::Graph::pie->new(500, 600));

Replies are listed 'Best First'.
Re^3: doughnut charts with gd:graph
by theravadamonk (Scribe) on Aug 01, 2018 at 04:15 UTC

    >> You already have the image as a pie so why not just overlay a background-coloured circle on the middle?

    This time I used GD::Image to draw a circle and inserted it to the pie chart.

    Here's the code. It works...

    #!/usr/bin/perl use CGI ':standard'; use strict; use warnings; use GD; use GD::Graph::pie; my @df = `df -P /var`; my ($used, $free) = (split (/\s+/, $df[1]))[2,3]; # Both the arrays should have same number of entries. my @data = (['Used', 'Free'], [$used, $free]); my $mygraph = GD::Graph::pie->new(175, 175); $mygraph->set( title => '/var Partition' , '3d' => 0, #'3d' => 1, #label => 'Label', transparent => 1, ) or warn $mygraph->error; $mygraph->set_value_font(GD::gdMediumBoldFont); my $myimage = $mygraph->plot(\@data) or die $mygraph->error; my $circleImg = new GD::Image( 100,100 ); # allocate some colors my $green = $circleImg->colorAllocate(0,255,0); my $white = $circleImg->colorAllocate(255,255,255); my $blue = $circleImg->colorAllocate(0,0,255); #$circleImg->transparent($green); #$circleImg->interlaced('true'); # Draw a blue circle $circleImg->arc(50,50,100,100,0,360,$blue); # And fill it with color $circleImg->fill(50,50,$white); $myimage->copy($circleImg,38,46,0,0,100,100); print "Content-type: image/png\n\n"; binmode STDOUT; print $myimage->png;

    Hv a Nice day to all perl Monks...