$query = "SELECT distinct date, priceInCents FROM META_VAL WHERE date >= DATE_SUB(NOW(), INTERVAL 7 DAY) ORDER BY date ASC"; $sth = $dbh->prepare($query); $sth->execute or die "SQL Error: $DBI::errstr\n"; while (my @result = $sth->fetchrow_array) { push @dates, $result[0]; push @prices, ($result[1]/100); } my $mygraph = Chart::Gnuplot->new( output => "chart.png", timeaxis => 'x', xlabel => 'Date', ylabel => 'Price', } my $data = Chart::Gnuplot::DataSet->new( xdata => \@dates, ydata => \@prices, style => 'linespoints', timefmt => '%Y-%m-%d $H:%M:%S', # input time format ); $mygraph->plot2d($data);