Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

3d bar chart

by feloniousMonk (Pilgrim)
on Mar 11, 2004 at 19:31 UTC ( [id://335940]=perlquestion: print w/replies, xml ) Need Help??

feloniousMonk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

So I've been given the task of creating a 3D bar chart. I've created plenty of 2D charts using GD::Graph but have not yet been able to find a suitable 3D equivalent.

Any thoughts?

Thanks,
-felonious

Replies are listed 'Best First'.
Re: 3d bar chart
by b10m (Vicar) on Mar 11, 2004 at 19:33 UTC

    GD::Graph3D GD::Graph3d ?

    Update: it's 3d, not 3D ;)

    --
    b10m

    All code is usually tested, but rarely trusted.
      Ah, yes, thanks :-)

      Wonder why I didn't find that, spent a while on cpan before asking here too...
Re: 3d bar chart
by zentara (Archbishop) on Mar 11, 2004 at 19:45 UTC
    Here is a sample script:
    #!/usr/bin/perl use strict; use warnings; use GD::Graph::bars3d; # sample data my @data = (30, 45, 36, 42, 40, 44, 41, 39, 35, 46, 43, 38); my @dt = ('2002-10-10 00:00:00', '2002-10-10 01:00:00', '2002-10-10 02 +:00:00', '2002-10-10 03:00:00', '2002-10-10 04:00:00', '2002-10-10 05:00:00', '2002-10-10 06:00:00', '2002-10-10 07:00:00', '2002-10-10 08:00:00', '2002-10-10 09:00:00', '2002-10-10 10:00:00', '2002-10-10 11:00:00'); # setup the color set my @colors; for my $datum (@data) { push(@colors, get_color($datum)); } # create the data set for the graph my @dataset = (\@dt, \@data); # create the new graph my $graph = GD::Graph::bars3d->new( 400, 300 ); # setup the graph options $graph->set( transparent => '0', bgclr => 'lgray', boxclr => 'white', fgclr => 'white', x_label => 'Date / Time', y_label => 'Number of Woozles Sold', title => 'World Wide Woozle Sales', dclrs => \@colors, cycle_clrs => 1, # this is mandatory for this to work x_labels_vertical => 1, ); # plot the graph my $gd = $graph->plot(\@dataset); # create a PNG file of the graph open(IMG, ">$0.png") or die $!; binmode IMG; print IMG $gd->png; # returns the color name based on the value given # this is only an example # you should base your numbers off of your actual data sub get_color { my $value = shift; return "dpurple" if ($value < 34); return "lpurple" if ($value < 36); return "blue" if ($value < 38); return "green" if ($value < 40); return "yellow" if ($value < 42); return "orange" if ($value < 44); return "red"; }

    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://335940]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-25 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found