Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

>> 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-03-29 08:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found