#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;
# Prepare data to plot
my @x = (1 .. 7);
my (@y1, @y2) = ();
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);
push(@y1, $y1);
push(@y2, $y2);
}
# Chart object
my $chart = Chart::Gnuplot->new(
output => "mixed.png",
xrange => [0, 8],
yrange => [0, 4],
imagesize => "0.45,0.45",
);
# DataSet object of the bar
my $barData = Chart::Gnuplot::DataSet->new(
xdata => \@x,
ydata => \@y1,
style => "boxes",
color => "#77CC77",
fill => {density => 0.4},
width => 3,
);
# DataSet object of the line
my $lineData = Chart::Gnuplot::DataSet->new(
xdata => \@x,
ydata => \@y2,
style => "lines",
color => "#DD8888",
width => 5,
);
# Plot the graph
$chart->plot2d($barData, $lineData);