I am trying to create a graph with GD::Graph::hbars ; My issue is with the length of the label text in the vertical axis. I would like to break up each label into 2 lines, but there seems to be no option to do that. (I tried inserting a \n in the label string, but that just puts in a strange character in the final graph) In the piece of code below, I want each label in the vertical axis to break after either 'Vision 3D' or 'Core 100'. The picture output by the code below is http://dl.dropbox.com/u/1172/v3d_usb_perf.gif ; Any suggestions towards helping convert the currently ugly graph into a viewable one would be deeply appreciated :)
use strict; use GD::Text ; use GD::Graph::hbars ; use GD::Graph::colour; my @data = ( ["Vision 3D NEC USB 3.0","Vision 3D Fresco Logic USB 3.0","Vision 3D N +EC USB 2.0","Core 100 NEC USB 3.0"], # Read benchmark [93.2, 84.8, 29.8, 80.5], # Write benchmark [77.1, 83.7, 23.2, 73], ); my @names = qw/v3d_usb_perf/; my @dim = (640,480); for my $my_graph (GD::Graph::hbars->new(@dim)) { my $name = shift @names; print STDERR "Processing $name\n"; $my_graph->set( t_margin => 15, b_margin => 15, l_margin => 15, r_margin => 15, x_label => '', y_label => 'Transfer Bandwidth (MB/s)', title => 'Average USB Transfer Rates in ASRock HTPCs (MB/s)', y_max_value => 100, y_tick_number => 5, y_label_skip => 1, y_tick_offset => 1, line_width => 1, bar_spacing => 2, show_values => 1, borderclrs => [ qw(black) ], # bgclr => 'gray', shadow_depth => 1, bargroup_spacing => 50, accent_treshold => 200, transparent => 0, box_axis => 0, ); $my_graph->set( dclrs => [ qw(lblue lgreen) ] ); $my_graph->set_legend(qw(Read Write)); $my_graph->set_title_font( GD::Font->Giant ); $my_graph->set_x_label_font( GD::Font->MediumBold ); $my_graph->set_y_label_font( GD::Font->MediumBold ); $my_graph->set_legend_font( GD::Font->MediumBold ); $my_graph->set_x_axis_font( GD::Font->MediumBold ); $my_graph->set_y_axis_font( GD::Font->MediumBold ); $my_graph->set_values_font( GD::Font->MediumBold ); $my_graph->plot(\@data); save_chart($my_graph, $name); } sub save_chart { my ($chart, $name) = @_; local(*OUT); my $ext = $chart->export_format; open(OUT, ">$name.$ext") or die "Cannot open $name.$ext for write: $!"; binmode OUT; print OUT $chart->gd->$ext(); close OUT; }

In reply to Formatting Labels in GD Graphs by ganeshts

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.