Hi Monks
I want to create a bar plot with GD-Graph, but I do want to set the colours of the various legends manually. I read the data from a file and store them in an array, but how can the program "understand" how many variables I have and find different colour for each one?
#script for table of summarized results for whole dataset use GD::Graph::bars; use GD::Graph::hbars; @methods=(); #keeps methods' names @data=(); #keeps all data @all=(); #keeps everything open IN, $ARGV[0]; while (<IN>) { chomp $_; if($_=~/^METHOD\t(.*)/) #1st line is the Header line { $header_all = $1; @split_header = split(/\t/, $header_all); } else { $method_line = $_; #lines with the methods @split_method = split(/\t/, $method_line); $method_name= shift (@split_method); push @methods, $method_name; push @data, @split_method; } } close IN; @all = ( @methods, @data); $legend = "@methods"; $name = "TEST"; $my_graph = GD::Graph::bars->new; $my_graph->set( #x_label => 'X Label', #y_label => 'Y label', #title => 'Stacked Bars (incremental)', #y_max_value => 50, #y_tick_number => 10, #y_label_skip => 2, cumulate => 2, borderclrs => $my_graph->{dclrs}, #cycle_clrs => 2, bar_spacing => 4, #shadow_depth => 4, transparent => 0, ); $my_graph->set_legend(@split_methods); $my_graph->plot(\@all); save_chart($my_graph, $name); sub save_chart { $chart = shift or die "Need a chart!"; $name = shift or die "Need a name!"; local(*OUT); $ext = 'png'; open(OUT, ">$name.$ext") or die "Cannot open $name.$ext for write: $!"; binmode OUT; print OUT $chart->gd->$ext(); close OUT; }

In reply to Generating X number of colours in GD-Graph? by Anonymous Monk

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.