Tedy Grey Tedy Grey - 10 months ago 32
Perl Question

Setting GD::Graph chart dimension and bar sizes

I create the following plot with

. The chart bars are way too concentrated and it's not really visible.


My expectation would be something more like this.

Visible plot

My code looks like this:

my $my_graph = GD::Graph::bars->new();

x_label => 'Numbers',
y_label => 'Occurance',
title => 'Plot',
) or warn $my_graph->error;`

What are the settings for the plot size and for the bars size (horizontal)?


The module's documentation describes the following options very clearly

width, height

The width and height of the canvas in pixels Default: 400 x 300.

NB At the moment, these are read-only options. If you want to set the size of a graph, you will have to do that with the new method.



The width of a bar in pixels. Also see bar_spacing. Use bar_width If you want to have fixed-width bars, no matter how wide the chart gets. Default: as wide as possible, within the constraints of the chart size and bar_spacing setting.

I suggest that the best option for making the bars wider is to reduce their number, or to increase the width of the graph