Goodly Monks:

I've been using GD and GD::Graph successfully for some time, but I've recently run into a bug, either in my understanding or in one of the utilities. ;-)
use GD; use GD::Graph::linespoints; use GD::Graph::bars3d; @colors = ('red', 'green', 'blue', 'gold', 'magenta'); @colorvals = ([255,0,0], [0,204,0],[0,0,255],[255,204,0],[255,0,255] +); . . . $linechart = GD::Graph::linespoints->new(640, 640) or die "no char +t!\n"; $linechart->set( # dclrs => [@colors], line_width => 3, x_label => 'Domain of ' . uc($fdat{domain}) . 's', y_label => 'Mean Value in ' . $ulong, title => "Test: '" . $fdat{testn} . "' Compared by +" . uc($fdat{compare}), x_labels_vertical => 1) or die $linechart->error; $linechart->set_x_axis_font(gdSmallFont); $linechart->set_y_axis_font(gdSmallFont); $gd = $linechart->plot(\@gdata) or die $linechart->error; . . . $legend = new GD::Image($gdwidth,$gdheight); $legend->transparent($legend->colorAllocate(255,255,255)); $legend->rectangle(0,0,$gdwidth-1,$gdheight-1,$legend->colorAlloca +te(0,0,0)); for ($cn=0;$cn<@comps;$cn++) { . . . $thiscolor = $legend->colorAllocate($colorvals[$cn][0],$colorval +s[$cn][1],$colorvals[$cn][2]); $legend->string(gdSmallFont,2,5+($cn*18),$rowdata,$thiscolor); }
I see two behaviors that are undesirable. If I uncomment the dclrs line in the first set() command, sometimes the whole graph will fail claiming 'Illegal modulus zero in line 443 of GD.pm'. I've tried setting GD::Image to truecolor status, changing my colors to websafe, etc., but as soon as I try setting that palette myself, it bombs erratically. Often, a simple refresh will clear it, too.

The second bug that shows up seems to be related. In this case, I'm crating a GD image directly, without using GD::Graph. If I have five lines with different colors, all color allocation gets turned off and everything comes out in black.

Does anybody have experience with such a problem?

In reply to GD and colors by samizdat

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.