#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;
# Prepare data to plot
my @x = (1 .. 4);
my (@y1, @y2, @y3) = ();
for (my $i = 0; $i < @x; $i++)
{
    my $y1 = sqrt($x[$i]) + 1.5*(rand()-0.5);
    my $y2 = sqrt($x[$i]) + 1.5*(rand()-0.5);
    my $y3 = sqrt($x[$i]) + 1.5*(rand()-0.5);
    push(@y1, $y1);
    push(@y2, $y2);
    push(@y3, $y3);
}
# Chart object
my $chart = Chart::Gnuplot->new(
    output    => "bar.png",
    xrange    => [-1, 4],
    yrange    => [0, 3],
    imagesize => "0.45,0.45",
);
# DataSet object of the data set A
my $dataA = Chart::Gnuplot::DataSet->new(
    xdata => \@x,
    ydata => \@y1,
    style => "histograms",
    color => "#DD8888",
    fill  => {density => 0.5},
);
# DataSet object of the data set B
my $dataB = Chart::Gnuplot::DataSet->new(
    xdata    => \@x,
    ydata    => \@y2,
    style    => "histograms",
    color    => "#88DD88",
    fill     => {density => 0.5},
    linetype => 'solid',
);
# DataSet object of the data set C
my $dataC = Chart::Gnuplot::DataSet->new(
    xdata    => \@x,
    ydata    => \@y3,
    style    => "histograms",
    color    => "#8888DD",
    fill     => {density => 0.5},
    linetype => 'solid',
);
# Plot the graph
$chart->plot2d($dataA, $dataB, $dataC);