[Chicago-talk] Printing the correct x-axis in GD::Graph

Jay Strauss me at heyjay.com
Fri Mar 12 09:33:41 CST 2004


Hi,

I figured I'd ask my own GD::Graph question.

Below is my script.  I'd like to print only the first day of the month (that
has data) on the x-axis.  So with the script below, I'd like the x-axis to
contain ONLY:

2003/11/14
2003/12/01
2004/01/01
2004/02/02
2004/03/01

Reading the docs I got the impression I could fill my x array with undefs
everywhere but the places I wanted a value, but that doesn't work.  Instead
it smears data on top of each other.

Any pointers?

Thanks
Jay


#!/usr/bin/perl

use strict;
use GD::Graph::linespoints;

my $prvMon;
my (@a, @b);

while (<DATA>) {
    chomp;
    my ($a, $b) = split(/\s+/);
    my ($yr, $mon, $day) = split(/\//,$a);

    $a = undef if $mon == $prvMon;
    $prvMon = $mon;

    push @a, $a;
    push @b, $b;
}

my @s = sort {$a <=> $b} @b;

my $graph = GD::Graph::linespoints->new(800, 600);

$graph->set(
    x_label           => 'X Label',
    y_label           => 'Y label',
    title             => 'Some simple graph',
    y_max_value       => $s[-1],
    y_tick_number     => 8,
    y_label_skip      => 2,
    x_ticks           =>1,
    x_plot_values     => 1,
);

my $gd = $graph->plot([\@a,\@b]);

open(IMG, '>file.png') or die $!;
binmode IMG;
print IMG $gd->png;


__DATA__
2003/11/14      962.92
2003/11/17      963.03
2003/11/18      964.35
2003/11/19      963.11
2003/11/20      961.88
2003/11/21      961.92
2003/11/24      962.03
2003/11/25      963.34
2003/11/26      963.37
2003/11/27      963.41
2003/11/28      963.45
2003/12/01      964.78
2003/12/02      965.25
2003/12/03      966.29
2003/12/04      966.75
2003/12/05      966.34
2003/12/08      965.87
2003/12/09      967.74
2003/12/10      963.03
2003/12/11       963.1
2003/12/12      964.23
2003/12/14       964.3
2003/12/15      965.01
2003/12/16      964.41
2003/12/17      966.49
2003/12/18      965.72
2003/12/19      965.11
2003/12/21      965.18
2003/12/22      967.11
2003/12/23      967.92
2003/12/24      967.25
2003/12/25      967.29
2003/12/26       969.5
2003/12/29      970.93
2003/12/30      971.41
2003/12/31      971.19
2004/01/01      971.19
2004/01/02      971.19
2004/01/05      971.48
2004/01/06      971.96
2004/01/07      965.72
2004/01/08      965.54
2004/01/09      967.06
2004/01/12      959.61
2004/01/13      963.36
2004/01/14      957.79
2004/01/15         956
2004/01/16      955.13
2004/01/18      955.13
2004/01/19      955.13
2004/01/20      957.09
2004/01/21      962.16
2004/01/22      963.42
2004/01/23       965.4
2004/01/24       965.4
2004/01/26      960.58
2004/01/27      968.93
2004/01/28      969.13
2004/01/29      966.07
2004/01/30      967.37
2004/01/31      967.29
2004/02/02      967.89
2004/02/03      968.31
2004/02/04      970.45
2004/02/05      969.32
2004/02/06      973.72
2004/02/08      973.81
2004/02/09      974.92
2004/02/10      974.42
2004/02/11      975.65
2004/02/12      976.83
2004/02/13      976.97
2004/02/16      976.97
2004/02/17      979.22
2004/02/18       979.4
2004/02/19      979.03
2004/02/20      977.28
2004/02/21      977.28
2004/02/22      977.28
2004/02/23      978.31
2004/02/24      979.28
2004/02/25         979
2004/02/26      979.54
2004/02/27      980.53
2004/02/29      980.61
2004/03/01       982.5
2004/03/02      982.42
2004/03/03       981.3
2004/03/04      981.91
2004/03/05      983.93
2004/03/08      982.69
2004/03/09      982.58
2004/03/10      977.31
2004/03/11      975.66
2004/03/12      974.54




More information about the Chicago-talk mailing list