please help with GD::Graph

Discussion in 'Perl Misc' started by bev_greg@yahoo.com, Jul 31, 2005.

  1. Guest

    I want to create a line graph that has more than 7 datasets, which
    looks like ([time], [interface 1 data], [interface 2 data], ......
    [interface 30 data]), I didn't find a way to distingush which line is
    the data for which interface except using @legend, does anyone know how
    many colors can be used, does it support more than 30 colors? or, is
    there a way that I can have a dataset name printed for each line in the
    graph? Thanks for your help.
     
    , Jul 31, 2005
    #1
    1. Advertising

  2. Bob Walton Guest

    wrote:

    > I want to create a line graph that has more than 7 datasets, which
    > looks like ([time], [interface 1 data], [interface 2 data], ......
    > [interface 30 data]), I didn't find a way to distingush which line is
    > the data for which interface except using @legend, does anyone know how
    > many colors can be used, does it support more than 30 colors? or, is
    > there a way that I can have a dataset name printed for each line in the
    > graph? Thanks for your help.
    >


    Please try to communicate in Perl, not some pseudo language. We
    speak Perl in this newsgroup. Also, please show what you have
    done so far, and state what it is that you thought it should do
    and what it actually did. Keep the code to as small as possible
    to illustrate your problem, and make it so anyone can
    copy/paste/run it.

    Your questions are readily answered by perusing the documentation
    for the GD::Graph module and its submodules.

    Per that documentation, by default, datasets cycle through 7
    colors, but you can add to that list easily using the dclrs method.

    You can add additional colors to the defined colors list with the
    add_colour method of GD::Graph::colour. Using the colour_list
    function, one sees that there are actually 29 already-defined
    colors, so it looks like you would have to add only one more.

    Here is a crappy little program that draws a 30-line graph with
    each line in a different color:

    use GD::Graph::lines;
    use strict;
    use warnings;
    use Data::Dumper;
    use GD::Graph::colour qw:)lists :colours);
    add_colour(funky=>[23,234,127]);
    my @colors=colour_list(30);
    print Dumper(\@colors);
    my @data;
    for my $i(0..30){
    for my $j(0..5){
    $data[$i][$j]=$j,next if $i==0; #x labels
    $data[$i][$j]=rand(8);
    }
    }
    print Dumper(\@data);
    my $graph = GD::Graph::lines->new(1000, 800);
    $graph->set(
    x_label => 'X Label',
    y_label => 'Y label',
    title => 'Some simple graph',
    y_max_value => 8,
    y_tick_number => 8,
    y_label_skip => 2
    ) or die $graph->error;
    $graph->set(dclrs=>\@colors);
    my $gd = $graph->plot(\@data) or die $graph->error;
    open(IMG, '>junk541.gif') or die $!;
    binmode IMG;
    print IMG $gd->gif;
    close IMG;

    HTH.
    --
    Bob Walton
    Email: http://bwalton.com/cgi-bin/emailbob.pl
     
    Bob Walton, Jul 31, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Sakkis
    Replies:
    1
    Views:
    473
    Szabolcs Nagy
    Jan 29, 2007
  2. Dr Ann Huxtable

    Missing Graph.h and (Graph.lib) woes - any help

    Dr Ann Huxtable, Dec 21, 2004, in forum: C Programming
    Replies:
    6
    Views:
    669
    Dr Ann Huxtable
    Dec 21, 2004
  3. Jef Driesen
    Replies:
    3
    Views:
    2,608
    mlimber
    Jan 24, 2006
  4. Almoni
    Replies:
    0
    Views:
    3,136
    Almoni
    Jan 17, 2010
  5. Emilio Mayorga
    Replies:
    6
    Views:
    375
    Martien Verbruggen
    Oct 8, 2003
Loading...

Share This Page