I am plotting a graph, using GD::Graph and I would like to put labels inside the graph at key locations along my lines.

I am able to get_hotspots() only after I plot. Then I need to create and draw the new text. If I display the data at this time my labels will not appear. I need to plot again, then my labels will appear. However, when I plot twice like this I get a ghosted image of of the entire graph with the second image being stretched so it is noticeable.

In the examples, sample71.pl does plot, get_hotspots(), draw and then save_chart through save.pl and it has no problem. I am writing CGI so I just print an img tag with src="data:.." to display the image.

Here is a code snippet

# need this plot in order for hotspots to have data my $plotdata = $graph->plot($rows)->gif; my $gd = $graph->gd; my $red = $gd->colorResolve(255,0,0); my @l = $graph->get_hotspot(1, 3); my ($x, $y) = ( ($l[1] + $l[3])/2, ($l[2] + $l[4])/2 ); my $gdta; $gdta = GD::Text::Align->new($gd, text => 'maximum', font => ['../Dustismo_Sans.ttf', GD::Font->Small], ptsize => 12, colour => $red, valign => 'bottom', halign => 'center', ) or warn $gdta->error; $gdta->draw($x, $y + 2); # must re-plot to get hotspots visible # without this call to plot, the graph is fine (sans labels) # but with it I get labels and a ghosting problem $plotdata = $graph->plot($rows)->png; my $uri = URI->new("data:"); $uri->media_type("image/png"); $uri->data($plotdata); print qq(<img src="$uri" alt="Didn't work."></html>\n);
I tried throwing away the plotdata from either plot call but could not get what I wanted. Thanks in advance Mark

In reply to gd::graph hotspots by elmoz

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.