$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); #### 2015-03-02 10:09:00 4615 2015-03-02 20:22:00 4645 2015-03-03 10:30:00 4610 2015-03-03 20:36:00 4625 2015-03-04 10:43:00 4603 2015-03-04 20:49:00 4790 2015-03-05 10:54:00 4724 2015-03-05 20:54:00 4834