3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
|
use Chart::Gnuplot; |
|
6 |
use Data::Dump qw(dump); |
use Data::Dump qw(dump); |
7 |
|
|
8 |
sub date { |
sub date { |
|
my ( $x, $y, $path ) = @_; |
|
9 |
|
|
10 |
$path ||= '/tmp/date.png'; |
my @plot; |
11 |
|
my $uid = ''; |
12 |
|
|
13 |
# Create the chart object |
foreach my $datafile ( @_ ) { |
14 |
my $chart = Chart::Gnuplot->new( |
my $name = $datafile; |
15 |
output => $path, |
$name =~ s/^.+date,// || next; |
16 |
xlabel => 'Date axis', |
$name =~ s/\.txt$//; |
|
timeaxis => "x", # declare that x-axis uses time format |
|
|
); |
|
|
|
|
|
# Data set object |
|
|
my $data = Chart::Gnuplot::DataSet->new( |
|
|
xdata => $x, |
|
|
ydata => $y, |
|
|
style => 'linespoints', |
|
|
timefmt => '%Y-%m-%d', # input time format |
|
|
); |
|
17 |
|
|
18 |
# Plot the graph |
push @plot, qq|"$datafile" using 1:2 title "$name" with linespoints|; |
19 |
$chart->plot2d($data); |
$uid .= $name; |
20 |
|
} |
21 |
|
|
22 |
|
my $path = "/tmp/sack.gnuplot.$uid.png"; |
23 |
|
|
24 |
|
open(my $gnuplot, '|-', 'gnuplot') || die "gnuplot $!"; |
25 |
|
print $gnuplot qq| |
26 |
|
|
27 |
|
set terminal png |
28 |
|
set output '$path' |
29 |
|
|
30 |
|
set xdata time |
31 |
|
set timefmt "%Y-%m-%d" |
32 |
|
set format x "%d.%m." |
33 |
|
#set xrange [ "2009-01-01":"2010-01-01" ] |
34 |
|
#set yrange [ 0 : ] |
35 |
|
|
36 |
|
plot |, join(',', @plot); |
37 |
|
|
38 |
|
close($gnuplot); |
39 |
|
|
40 |
warn "gnuplot $path ", -s $path, " bytes\n"; |
warn "gnuplot $path ", -s $path, " bytes\n"; |
41 |
|
|