1. use use strict; and use warnings. Always.
2. Try and fix up your indentation, particularly your %hash assignment list. Currently, it would be very easy for a typo or omission to slip by unnoticed.
3. The add_datafile method says if you're using the set mode flag, then each line in your datafile needs to be an entire dataset.
one of the mountain test scripts has this kind of structure, perhaps that may shed some light on what you should be inputing.
my @data = (
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 3, 7, 8, 2, 4, 8.5, 2, 5, 9],
[ 4, 2, 5, 6, 3, 2.5, 3, 3, 4],
[ 7, 3, 2, 8, 8.5, 2, 9, 4, 5],
);
My guess is that if you're getting duplicates in your x axis, its becuase you have duplicates in your dataset. I could be wrong, but it looks like the module expects you to already have dealt with duplicates via your own algorithm. (i.e. it doesn't do that part for you...).
Using the test scripts data as an example, each placing has only 1 column. There aren't two 1st's, or two 2nd's, etc. | [reply] [d/l] [select] |
29/04/2010-00.00 29/04/2010-00.30 29/04/2010-01.00 29/04/2010-01.30 29
+/04/2010-02.00 29/04/2010-02.30 29/04/2010-03.00 29/04/2010-03.30 29/
+04/2010-04.00 29/04/2010-04.30 29/04/2010-05.00 29/04/2010-05.30 29/0
+4/2010-06.00 29/04/2010-06.30 29/04/2010-07.00 29/04/2010-07.30 29/04
+/2010-08.00 29/04/2010-08.30 29/04/2010-09.00 29/04/2010-09.30 29/04/
+2010-10.00 29/04/2010-10.30 29/04/2010-11.00 29/04/2010-11.30 29/04/2
+010-12.00 29/04/2010-12.30 29/04/2010-13.00 29/04/2010-13.30 29/04/20
+10-14.00 29/04/2010-14.30 29/04/2010-15.00 29/04/2010-15.30 29/04/201
+0-16.00 29/04/2010-16.30 29/04/2010-17.00 29/04/2010-17.30 29/04/2010
+-18.00 29/04/2010-18.30 29/04/2010-19.00 29/04/2010-19.30 29/04/2010-
+20.00 29/04/2010-20.30 29/04/2010-21.00 29/04/2010-21.30 29/04/2010-2
+2.00 29/04/2010-22.30 29/04/2010-23.00 29/04/2010-23.30
2 3 1 1 2 2 1 2 2 3 2 1 1 1 1 4 3 3 2 1 2 3 1 1 2 2 1 2 2 3 2 1 1 1 1
+4 3 3 2 1 2 3 1 1 2 2 1 2
| [reply] [d/l] |
Ok, those duplicates were actually Chart::Mountain trying to be helpful as it had inserted halfticks into the Y axis to try and improve the overall readability of the graph.
At some point in your travels, you unfortunately brought yourself undone by setting precision => 0, which caused those halfticks to round down, 4.5 to 4, 3.5 to 3 etc...
What you should be using is 'integer_ticks_only' => 1,.
I don't know what $popname was sposed to do, so I removed it. And it makes far more sense to declare the graph options in a single list rather than some up top in a separate hash, and others hidden lower down...
#!/usr/bin/perl
use strict;
use warnings;
use Chart::Mountain;
my $filename = $ARGV[0];
my $g = Chart::Mountain->new(1000,500);
$g->add_datafile( "$filename", 'set' );
$g->set ( 'title' => 'Video Server Play Daily Hourly
+ Report',
'grid_lines' => 'true',
'y_label' => 'Numero Streams',
'x_label' => 'Dates',
'include_zero' => 1,
'x_ticks' => 'vertical',
'tick_label_font' => (GD::Font->Giant),
'title_font' => (GD::Font->Giant),
'colors' => {'dataset0' => [0,255,0]},
'integer_ticks_only' => 1,
'misc' => [0,0,0],
);
$g->jpeg ("graph.jpg");
Data.txt:
29/04/2010-00.00 29/04/2010-00.30 29/04/2010-01.00 29/04/2010-01.30 29
+/04/2010-02.00 29/04/2010-02.30 29/04/2010-03.00 29/04/2010-03.30 29/
+04/2010-04.00 29/04/2010-04.30 29/04/2010-05.00 29/04/2010-05.30 29/0
+4/2010-06.00 29/04/2010-06.30 29/04/2010-07.00 29/04/2010-07.30 29/04
+/2010-08.00 29/04/2010-08.30 29/04/2010-09.00 29/04/2010-09.30 29/04/
+2010-10.00 29/04/2010-10.30 29/04/2010-11.00 29/04/2010-11.30 29/04/2
+010-12.00 29/04/2010-12.30 29/04/2010-13.00 29/04/2010-13.30 29/04/20
+10-14.00 29/04/2010-14.30 29/04/2010-15.00 29/04/2010-15.30 29/04/201
+0-16.00 29/04/2010-16.30 29/04/2010-17.00 29/04/2010-17.30 29/04/2010
+-18.00 29/04/2010-18.30 29/04/2010-19.00 29/04/2010-19.30 29/04/2010-
+20.00 29/04/2010-20.30 29/04/2010-21.00 29/04/2010-21.30 29/04/2010-2
+2.00 29/04/2010-22.30 29/04/2010-23.00 29/04/2010-23.30
2 3 1 1 2 2 1 2 2 3 2 1 1 1 1 4 3 3 2 1 2 3 1 1 2 2 1 2 2 3 2 1 1 1 1
+4 3 3 2 1 2 3 1 1 2 2 1 2
| [reply] [d/l] [select] |
Here's a script to produce a plot with gnuplot, similar to Plot a spiral with gnuplot.
Note: this will write the plot to a file "plot.png" in the current directory, overwriting without asking. You may want to change the name before you run.
use warnings; use strict;
use IO::Handle;
use File::Temp "tempfile";
my @date_str = qw(
29/04/2010-00.00 29/04/2010-00.30 29/04/2010-01.00
29/04/2010-01.30 29/04/2010-02.00 29/04/2010-02.30
29/04/2010-03.00 29/04/2010-03.30 29/04/2010-04.00
29/04/2010-04.30 29/04/2010-05.00 29/04/2010-05.30
29/04/2010-06.00 29/04/2010-06.30 29/04/2010-07.00
29/04/2010-07.30 29/04/2010-08.00 29/04/2010-08.30
29/04/2010-09.00 29/04/2010-09.30 29/04/2010-10.00
29/04/2010-10.30 29/04/2010-11.00 29/04/2010-11.30
29/04/2010-12.00 29/04/2010-12.30 29/04/2010-13.00
29/04/2010-13.30 29/04/2010-14.00 29/04/2010-14.30
29/04/2010-15.00 29/04/2010-15.30 29/04/2010-16.00
29/04/2010-16.30 29/04/2010-17.00 29/04/2010-17.30
29/04/2010-18.00 29/04/2010-18.30 29/04/2010-19.00
29/04/2010-19.30 29/04/2010-20.00 29/04/2010-20.30
29/04/2010-21.00 29/04/2010-21.30 29/04/2010-22.00
29/04/2010-22.30 29/04/2010-23.00 29/04/2010-23.30
);
my @value = qw(
2 3 1 1 2 2 1 2 2 3 2 1 1 1 1 4 3 3 2 1 2 3 1 1 2 2
1 2 2 3 2 1 1 1 1 4 3 3 2 1 2 3 1 1 2 2 1 2
);
my($T,$N) = tempfile("plot-XXXXXXXX", "UNLINK", 1);
for my $k (0 .. @value - 1) {
say $T $date_str[$k], " ", $value[$k];
}
close $T;
open my $P, "|-", "gnuplot" or die;
printflush $P qq[
unset key
set title "Video Server Play Daily Hourly Report"
set xdata time
set timefmt "%d/%m/%Y-%H.%M"
set format x "%d/%m-%H.%M"
set xtics rotate
set yrange [0:] noreverse
set terminal png giant size 1000,500
set output "plot.png"
plot "$N" using 1:2 with filledcurves y1=0
];
close $P;
__END__
Update 2012-01-28: added the statement close $T; which fixes a possible bug where the handle $T is not flushed; this fix is propagated from Plot a spiral with gnuplot.
| [reply] [d/l] [select] |