TTF fontar och svenska tecken i GD::Graph
#!/usr/bin/perl
# "module path"
BEGIN {
my $base_module_dir = ( getpwuid($>) )[7] . '/perl/';
unshift @INC, map { $base_module_dir . $_ } @INC;
}
use CGI qw/:standard/;
use GD::Graph;
use GD::Graph::bars;
use GD::Graph::colour;
use GD::Text;
use encoding 'utf8';
@data = (
["första", "andra", "tredje", "fjärde", "femte", "sjätte"],
[1, 2, 5, 6, 3, 1.5],
[sort {$a <=> $b} (1, 2, 5, 6, 3, 1.5)]
);
my $graph = GD::Graph::bars->new(600, 300);
$graph->set_legend("foo", "bar");
# Diverse egenskaper
$graph->set(
x_label => 'y-axeln',
y_label => 'x-axeln',
title => "Hålla mun och hacka!",
y_max_value => 8,
y_tick_number => 8,
y_label_skip => 2,
textclr => GD::Graph::colour::black,
labelclr => GD::Graph::colour::black,
axislabelclr => GD::Graph::colour::black,
fgclr => GD::Graph::colour::black,
legendclr => GD::Graph::colour::black
) or die $graph->error;
# Datafärgen
$graph->set( dclrs => [ qw(lgray gray) ] );
# Fontar
GD::Text->font_path("/usr/share/fonts/bitstream-vera");
$graph->set_title_font( "Vera", 14 );
$graph->set_legend_font( "Vera", 10 );
$graph->set_x_axis_font( "Vera", 9 );
$graph->set_x_label_font( "Vera", 11 );
$graph->set_y_axis_font( "Vera", 9 );
$graph->set_y_label_font( "Vera", 11 );
# Format och utdata
my $format = $graph->export_format;
print header("image/$format");
binmode STDOUT;
print $graph->plot(\@data)->$format();

This entry was posted in
Uncategorized. Bookmark the
permalink.