×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Building graph produces error "Cannot open gdgraph1.png:Permission denied"

Building graph produces error "Cannot open gdgraph1.png:Permission denied"

Building graph produces error "Cannot open gdgraph1.png:Permission denied"

(OP)
Hi,
I’d like to build a graph using Perl, I know nothing about using GD module but I thought Google will help-I was wrong.
I Googled bunch of examples but it seems they all producing same error “Cannot open gdgraph1.png:Permission denied”.
I could use Excel but want to use Perl.My data table is very simple:
Cell Usage
1 4 Days 15:16:38
2 4 Days 13:40:01
3 4 Days 17:20:56
4 4 Days 20:01:30
5 4 Days 05:32:38
6 3 Days 23:06:11
7 1 Days 22:52:54
8 2 Days 11:45:33
9 2 Days 10:57:24
10 2 Days 09:52:05
11 2 Days 12:22:11
12 0 Days 04:39:51

I still cannot find the button for posting codes :)

Here is a script I Googled that spits the same error:

#!/usr/local/bin/perl
use strict ;
use warnings ;
use diagnostics ;
use Carp;
use GD::Graph::bars;

my %dataset = ( 1 => 3,
2 => 17,
3 => 34,
4 => 23,
5 => 25,
6 => 20,
7 => 12,
8 => 3,
9 => 1
);

# create new image
my $graph = new GD::Graph::bars(600, 300);

# discover maximum values of x and y for graph parameters
my( $xmax) = sort {$b <=> $a} keys %dataset;
my( $ymax) = sort {$b <=> $a} values %dataset;
# how many ticks to put on y axis
my $yticks = int($ymax / 5) + 1;

# define input arrays and enter 0 if undefined x value
my(@xsizes) = (0 .. $xmax);
my(@ycounts) = ();
foreach my $x (@xsizes) {
if ( defined $dataset{$x}) {
push @ycounts, $dataset{$x};
}else{
push @ycounts, 0;
}
}

# set parameters for graph
$graph->set(
transparent => 0,
title => "Summary of mutation data",
x_label => 'Mutants per cluster',
y_label => 'Number of mutants',
x_all_ticks => 1,
y_all_ticks => 0,
y_tick_number => $yticks,
zero_axis => 0,
zero_axis_only => 0,
);

# plot the data on the graph
my $gd = $graph->plot(
[ xsizes,
ycounts
]
);

# output file
my $pngfile = "gdgraph1.png";
unless(open(PNG, ">$pngfile")) {
croak "Cannot open $pngfile:$!\n";
}

# set output file handle PNG to binary stream
# (this is important sometimes, for example doing
# GCI programming on some operating systems
binmode PNG;

# print the image to the output file
print PNG $gd->png;

Thank you for you help!
Tester_V

RE: Building graph produces error "Cannot open gdgraph1.png:Permission denied"

Hi

As far as I see, the only problem is the passing of data arrays. Those are barewords, need references :

CODE --> Perl ( fragment )

# plot the data on the graph
my $gd = $graph->plot(
    [
        \@xsizes,
        \@ycounts
    ]
); 

Regarding the error message you quoted, sounds like the Perl script has no permission to write in the current directory. Try writing elsewhere.

Quote (Tester_V)

I still cannot find the button for posting codes :)

Feherke.
feherke.github.io

RE: Building graph produces error "Cannot open gdgraph1.png:Permission denied"

(OP)
Thank you for the replay Feherke!

Do you or anyone knows an example of a working building graphs code, the whole code?
Not just snippets?
It is hard to understand without seen the whole script how it all works.
I do not know what that means exactly, "passing of data arrays. Those are barewords, need references"
Does it mean my data array is my data (see below)
And it needs to be passed as a reference array?

CElls, Usage
1,4 Days 15:16:38
10,2 Days 09:52:05
11,2 Days 12:22:11
12,0 Days 04:39:51
2,4 Days 13:40:01
3,4 Days 17:20:56
4,4 Days 20:01:30
5,4 Days 05:32:38
6,3 Days 23:06:11
7,1 Days 22:52:54
8,2 Days 11:45:33
9,2 Days 10:57:24

RE: Building graph produces error "Cannot open gdgraph1.png:Permission denied"

Hi

I mean that I only added those highlighted characters to your code in the $graph->plot() call and got this gdgraph1.png file :

Feherke.
feherke.github.io

RE: Building graph produces error "Cannot open gdgraph1.png:Permission denied"

(OP)
Thank you!
It is interesting....

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close