Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I don't know how pretty, but you can judge for yourself.

http://crazyinsomniac.perlmonk.org/images/jcgraph.png

I'm trying to improve this, help is welcome. As it stands now, i think it looks pretty good. Feel free to play with the colors/fonts.

#!/usr/bin/perl -w use strict; use GD::Graph::bars3d; use GD::Graph::Data; use GD::Graph::colour qw{ add_colour colour_list }; my $username = 'crazyinsomniac'; my $month = 'April'; my $year = '2002'; my @days = ( [1..30], [qw{ 10 1 -1 22 33 1 6 7 4 8 9 34 112 -2 -12 33 22 33 1 6 7 22 33 1 6 7 66 -66 0 1 }], ); my $graph = new GD::Graph::bars3d( 600, 400 ); add_colour('#66CC66'); add_colour('#00fbff'); add_colour('#000000'); $graph->set( y_label => 'XP change', # xp is not Reputation, thanks grinder x_label => 'DAY OF MONTH', box_axis => 1, x_tick_number => undef, # accentclr => '#000000', # this be the bar box edges accentclr => '#009999', # this be the bar box edges # dclrs => [ map{'#66CC66'} 1..@days ], # data color dclrs => [ map{'#00fbff'} 1..@days ], # data color title => "${username}'s XP gains/losses per day for $month, $y +ear" ) or die "$!"; my $days = GD::Graph::Data->new(); $days->copy_from(\@days); $graph->set(show_values => 1 ); ## show values $graph->set_values_font(GD::gdMediumBoldFont); my $gd = $graph->plot( $days ); $gd->interlaced('true'); open(FOUT,'>'.__FILE__.'.png') or die $!; binmode(FOUT); print FOUT $gd->png; close(FOUT)
update: ya know, caching these chart images might be nice, so you can do a per month lookup, with the current month being dynamic of course .

update: i overheard jcwren say something in the cb, so i tweaked a little more (stuff in readmore)

http://crazyinsomniac.perlmonk.org/images/jcgraph2.png
#!/usr/bin/perl -w =head JC Graph This was written for chris, aka jcwren, the greatest isp on earth, in response to http://perlmonks.org/index.pl?node_id=171725 In particular, it was written to replace the baaad php chart generation counterpart for use at http://www.tinymicros.com/pm/index.php?goto=PlotChart&nodeid=10277 It mimicks the look pretty well, even though GD::Graph::bars3d does/can not guarantee spacing between the bars and the text. I say it looks pretty good. You can see for your self at http://crazyinsomniac.perlmonk.org/images/jcgraph.png =cut use strict; use GD::Graph::bars3d; use GD::Graph::Data; use GD::Graph::colour qw{ add_colour colour_list }; my $username = 'crazyinsomniac'; my $month = 'April'; my $year = '2002'; my @days = ( [1..30], [qw{ 10 1 -1 22 33 1 6 7 4 8 9 34 112 -2 -12 33 22 33 1 6 7 22 33 1 6 7 66 -66 0 1 }], ); my $graph = new GD::Graph::bars3d( 700, 400 ); ## width probably best calculated ## using bar_spacing and the scalar(@$days[1]) add_colour('#66CC66'); add_colour('#00fbff'); add_colour('#000000'); $graph->set( y_label => 'XP change', # xp is not Reputation, thanks grinder x_label => 'DAY OF MONTH', box_axis => 1, # bar_width => 30, # doesn't work too well, bar_spacing => 10,# doesn't work too well, # esp if mixed together # also has to do with graph size values_space => 15, # how much to padd values_vertical => 1, # print values vertically x_tick_number => undef, # accentclr => '#000000', # this be the bar box edges accentclr => '#009999', # this be the bar box edges # dclrs => [ map{'#66CC66'} 1..@days ], # data color dclrs => [ map{'#00fbff'} 1..@days ], # data color title => "${username}'s XP gains/losses per day for $month, $y +ear" ) or die "$!"; my $days = GD::Graph::Data->new(); $days->copy_from(\@days); $graph->set(show_values => 1 ); ## show values $graph->set_values_font(GD::gdMediumBoldFont); my $gd = $graph->plot( $days ); $gd->interlaced('true'); open(FOUT,'>'.__FILE__.'.png') or die $!; binmode(FOUT); print FOUT $gd->png; close(FOUT)

 
______crazyinsomniac_____________________________
Of all the things I've lost, I miss my mind the most.
perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"


In reply to (crazyinsomniac:D) Re: Fame, Fortune, ChicksStuds, and XP! by crazyinsomniac
in thread Fame, Fortune, ChicksStuds, and XP! by jcwren

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 goofing around in the Monastery: (3)
As of 2024-04-19 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found