Hi there,
I've just started using Chart::Gnuplot and I'm having a problem where it's stacking all my time series data points at midnight versus spreading that data out across the day. It's seems like it doesn't recognize the H:M:S portion of the date I'm feeding it? I'm reading date/price values out of a MySQL table (from TIMESTAMP and INTEGER columns) and then plotting them out. The code looks like this...
$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);
...and some sample data looks like this...
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
...but like I said, the graph that is created has "islands" of points at midnight with no data points in between (like a normal stock price chart). I feel like I'm missing something obvious but my Google searches and Perl Monks searches haven't yielded anything.
Cheers and thanks!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.