gnuplot font problem (Perl CGI script)
- From: maho <mahmut.yilmaz@xxxxxxxxx>
- Date: Sun, 11 May 2008 02:49:08 -0700 (PDT)
I am trying to generate charts using gnuplot (in a Perl CGI script).
I am getting an error regarding fonts: "Could not find/open font when
opening font arial, using default".
gnuplot generates the image, but all the text looks bad, and text
rotations are omitted (causing unreadable text on the chart). I set
the environment variable 'GDFONTPATH' before calling gnuplot, but it
does not help at all. Anybody knows how to handle this problem?
Thanks!
I have the following Perl code in a CGI script:
# Create a stacked chart
sub CreateStackedChart
{
my ($ChartOption) = @_;
my $DataFile = $ChartOption->{DataFile};
my @Columns = @{$ChartOption->{Columns}};
# Remove the chart image if it already exists
if(-e "$ChartOption->{OutputFile}")
{
system("/tool/pandora64/bin/rm -f $ChartOption->{OutputFile}");
}
$ENV{'GDFONTPATH'} = "/usr/X11R6/lib/X11/fonts/msttcorefonts/";
open (FILE, "|/tool/pandora/.package/gnuplot-4.2.2/bin/gnuplot -
persist");
print FILE &GetCommonGPFileHeader($ChartOption);
print FILE <<EOC
set key invert reverse Left outside
set key autotitle columnheader
unset xtics
set xtics nomirror rotate by -90
set grid y
set border 3
set style data histograms
set style histogram rowstacked
set style fill solid border -1
set boxwidth 0.75
EOC
;
print FILE "plot '$DataFile' ";
my $Count=0;
my @PrintColumns=();
foreach my $Column (@Columns)
{
if(++$Count==1)
{
push(@PrintColumns, "using $Column:xtic(1)");
}
else
{
push(@PrintColumns, "'' using $Column");
}
}
print FILE join(', ',@PrintColumns);
close(FILE);
# Now wait until the file is created.
my $i = 0;
while (!-e "$ChartOption->{OutputFile}") {
sleep(1);
++$i;
die "Timed out waiting for gnuplot to render graph" if
($i == 5);
}
return $ChartOption->{OutputFile};
}
# Common chart options to be written to gnuplot run file
sub GetCommonGPFileHeader
{
my ($ChartOption) = @_;
my $FontSize = $ChartOption->{FontSize};
my $ChartWidth = $ChartOption->{ChartWidth};
my $ChartHeight = $ChartOption->{ChartHeight};
my $OutputFile = $ChartOption->{OutputFile};
my $ChartTitle = $ChartOption->{ChartTitle};
my $YLabel = $ChartOption->{YLabel};
my $Y2Label = $ChartOption->{Y2Label};
my $Str = "set terminal png transparent nocrop font arial $FontSize
size $ChartWidth, $ChartHeight\n";
$Str .= "set termoption noenhanced\n";
$Str .= "set title '$ChartTitle'\n";
$Str .= "set output '$OutputFile'\n";
$Str .= "set ylabel '$YLabel'\n";
$Str .= "set y2label '$Y2Label'\n";
return $Str;
}
.
- Follow-Ups:
- Re: gnuplot font problem (Perl CGI script)
- From: Ethan Merritt
- Re: gnuplot font problem (Perl CGI script)
- Prev by Date: Protect yourself against Operation Sudden Fall
- Next by Date: consistancy in help escape sequences
- Previous by thread: Protect yourself against Operation Sudden Fall
- Next by thread: Re: gnuplot font problem (Perl CGI script)
- Index(es):
Relevant Pages
|