File: datetime_3.pl

package info (click to toggle)
libchart-gnuplot-perl 0.23-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 944 kB
  • sloc: perl: 4,862; makefile: 113
file content (41 lines) | stat: -rwxr-xr-x 810 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;

# Change the date time format of the tic labels
# - the solution is the same as change the number format

# Date array
my @x = qw(
    2007-01-01
    2007-01-10
    2007-01-24
    2007-02-01
    2007-02-14
    2007-02-28
    2007-03-05
    2007-03-13
    2007-03-21
    2007-03-31
);
my @y = (1 .. 10);

# Create the chart object
my $chart = Chart::Gnuplot->new(
    output   => 'gallery/datetime_3.png',
    xtics    => {
        labelfmt => '%b-%y'
    },
    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
);

# Plot the graph
$chart->plot2d($data);