LAN-blog

LAN-blog

PERL i dammen

Linux and StuffPosted by Harleyman Sun, July 06, 2014 10:49:29
Blev spurgt af en kunde om man kunne lave nogle graffer for forskellige ting (inden for dambrug) og om de kan tegnes automatisk. Jamen det kan man da!
Brug en CronTab til at kald perl [ filenavn.pl ]
Uden Dataforbindelsen ser det sådan ud i Perl:

#!/usr/bin/perl

use strict;

use warnings;

use GD::Graph::bars;

my @products = (

'Fish Food', 'Fish', 'Money out' );

#! DATABASE KALD.... link -> mysql ;-)

my @sales_data = (

[ 2006, 2007, 2008, 2009 ], # X value labels

[ 54, 52, 50, 48 ], # Fish food

[ 38, 37, 30, 17 ], # FISH

[ 24, 28, 34, 44 ], # Money Out

);

my $graph = GD::Graph::bars->new(1024, 720);

$graph->set(

title => 'Product:FISH',

y_label => 'TON Shipped',

x_label => 'TON Sales by Year',

x_label_position => 0.5,

transparent => 0,

bgclr => 'white',

box_axis => 0,

fgclr => '#bbbbbb',

axislabelclr => '#333333',

labelclr => '#333333',

textclr => '#333333',

legendclr => '#333333',

dclrs => ['#fa782a', '#1daa3a', '#2d7296'],

borderclrs => [undef],

y_max_value => 60,

y_tick_number => 3,

tick_length => -4,

long_ticks => 0,

x_ticks => 0,

axis_space => 6,

bar_spacing => 1,

bargroup_spacing => 36,

legend_placement => 'RC',

legend_marker_width => 22,

legend_marker_height => 22

) or die $graph->error;

$graph->set_legend(@products);
#! Dette er en CentOS! Fonts kan ligge andre steder...

my $font_dir = '/usr/share/fonts/liberation';

my $font_file = "$font_dir/LiberationSans-Bold.ttf";

$graph->set_title_font($font_file, 26);

$graph->set_x_label_font($font_file, 21);

$graph->set_y_label_font($font_file, 21);

$graph->set_x_axis_font($font_file, 21);

$graph->set_y_axis_font($font_file, 21);

$graph->set_legend_font($font_file, 20);

my $gd = $graph->plot(\@sales_data) or die $graph->error;

my $filename = "$0.png";

open my $img, '>', $filename or die "open($filename): $!";

binmode $img;

print $img $gd->png;



  • Comments(1)//blog.deadmeat.dk/#post283