>> 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...


In reply to Re^3: doughnut charts with gd:graph by theravadamonk
in thread doughnut charts with gd:graph by theravadamonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.