Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 165811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:59:16+00:00 2026-05-11T11:59:16+00:00

I am writing a small program in Perl for my assignment and I am

  • 0

I am writing a small program in Perl for my assignment and I am new to Perl.

Code that I have written provides me with exactly the same values I need, but I am getting this error while creating bar chart.

Invalid data set: 0 at line 67 

Line 67 is marked with a comment in the code below.

The values stored in x-axis are:

40 44 48 52 64 76 83 104 105 148 149 249 431 665 805 1420 1500  

And y_axis are:

16 1  1 6 1 1 1 1 1 1 1 1 1 1 1 2 5  

Here’s my code:

use GD::Graph::bars;  open(CHECKBOOK,'c:\\Perl\\bin\\ip_packet_trace1.txt');  my $counter = -1; my @sizearray = {}; while ($record = <CHECKBOOK>) {     @array = split(/\t/,$record);     $counter++;     $sizearray[$counter] = $array[6];  }  $counter++;  my @array1 = sort {$a <=> $b} @sizearray; print '$counter\n'; print '@array1\n';   my @freq = {0...0};  foreach $elem (@array1){      my $s = $freq[$elem]+1;      $freq[$elem] = $s; }   my $size = @freq; my @x_axis = {}; my @y_axis = {};  my $count2 = -1;   for($i = 1; $i < $size; $i++){      my $elem = $freq[$i];      if($elem  and $elem > 0  ){          $count2++;          $x_axis[$count2] =  $i;          $y_axis[$count2] = $elem;     }  }   print '@x_axis \n'; print '@y_axis \n';     my $mygraph = GD::Graph::bars->new(500, 300); # line 67  $mygraph->set(x_label     => 'Month',  y_label     => 'Number of Hits',  title       => 'Number of Hits in Each Month in 2002',  ) or warn $mygraph->error;  my @data = {@x_axis,@y_axis};    my $myimage = $mygraph->plot(\@data) or die $mygraph->error;  open(IMG, '>C:\\image\\file.gif') or die $!;  binmode IMG;  print IMG $myimage->gif;  close IMG; 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:59:16+00:00Added an answer on May 11, 2026 at 11:59 am

    K. I tested and altered you code. The below code works. The array part that everyone mentioned was important, but not your only problem. The example in cpan, was of an anonymous array, so instead of passing @data 2 arrays, you just needed to pass 2 references to @data.

    #!/usr/bin/perl # use GD::Graph::bars;  my $size = @freq; my @x_axis = qw(40 44 48 52 64 76 83 104 105 148 149 249 431 665 805 1420 1500); my @y_axis = qw(16 1  1 6 1 1 1 1 1 1 1 1 1 1 1 2 5);  my $mygraph = GD::Graph::bars->new(500, 300); # line 67 $mygraph->set(x_label     => 'Month',             y_label     => 'Number of Hits',             title       => 'Number of Hits in Each Month in 2002', ) or warn $mygraph->error; my @data = (\@x_axis,\@y_axis); # the important part. my $myimage = $mygraph->plot(\@data) or die $mygraph->error;  open(IMG, '>helping_graph.gif') or die $!; binmode IMG; print IMG $myimage->gif; close IMG; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Polling is easy: Thread t = new Thread(new Runnable() {… May 12, 2026 at 1:13 am
  • Editorial Team
    Editorial Team added an answer try this : <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("News_Id") %>' NavigateUrl='<%#Eval("News_Id",… May 12, 2026 at 1:13 am
  • Editorial Team
    Editorial Team added an answer You can user LTRIM Oracle function: SQL> select ltrim(' hello… May 12, 2026 at 1:13 am

Related Questions

Please note - I am not looking for the right way to open/read a
I am writing a small program for my personal use to practice learning C++
I am writing a program in C++ using Eclipse. I want to compile it
I am writing some small program in C--some log in, log out, create account,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.