in reply to Re^2: How to calculate the column and print it in pie chart format using perl?
in thread How to calculate the column and print it in pie chart format using perl?

since you are serving it from your website that seems to be some wort of homebrew javascript package. As such we will be of little use in helping you prepare the statements that will properly call it. Possibly somebody else at work can help you with that

in the meantime you can work on getting your input data prepared correctly. From what you have shown %TABLE_DATA is empty.

Each time you reference $TABLE_DATA{5}{'ENTRY'} it will have the same data, it makes no difference if the label is Vcs or Adice. possibly you meant $TABLE_DATA{5}{'Vcs'} instead. what would even make more sense would be $TABLE_DATA{'jobs_running'}{'Vcs'}. we once showed you a way to translate the data returned by  my $table = $sth->fetchall_arrayref; into data of that form.

Because i would like this exercise in futility to end quicker i propose something like

sub print_overall_summary { my $str = shift; $DBH = &connect or die "Cannot connect to the sql server \n"; $DBH->do("USE $str;"); my $stmt="select queue_name,jobs_pending,jobs_running from summary o +rder by time desc ;"; ; my $sth = $DBH->prepare( $stmt ); $sth->execute() or print "Could not prepare_overall_summarydata"; print "<script language=\"javascript\" type=\"text/javascript\"> \n" +; print "\$(document).ready(function(){ \n"; %TABLE_DATA =(); my @sys=qw/Adice Incisive Vcs other/; my $table = $sth->fetchall_hashref; for my $r (@$table) { my $name='other'; for my $s (@sys){ if ($r->{queue_name)=~m/$s/i) {$name=$s; last;} } $TABLE_DATA{$name}{jobs_pending}+=$r->{jobs_pending}; $TABLE_DATA{$name}{jobs_running}+=$r->{jobs_running}; } for my $var(qw/running pending/) { my @parts=(); for my $s (@sys){ push @parts,'["'.$s.'",' .$TABLE_DATA{$s}{'jobs_'.$var} .']'; } print 'var data_'.$var.'=['.join(',',@parts).']'."\n"; } print " \n pieChart(\"placeholder39\",data_running,{title:\"<b><ce +nter>Jobs Running</center></b>\"});\n"; print " \n pieChart(\"placeholder41\",data_pending,{title:\"<b><ce +nter>Jobs Pending</center></b>\"});\n"; print "});"; print "</script>"; }
Untested, if there are syntax errors it s up to you to fix them.

notice you have not made any variables for data_machine or data_cpu so those piecharts would fail.

You need to talk to your boss about how these tasks are way beyond your abilities even though they are so simple. And how you need to get others to do your work for you.

Or you could make and effort to learn perl instead

Replies are listed 'Best First'.
Re^4: How to calculate the column and print it in pie chart format using perl?
by finddata (Sexton) on Mar 22, 2017 at 09:38 UTC
    why you had used hashref is it not possible with arrayref?

      You can easily convert between arrayref and hashref.

      If converting between arrays and hashes is problematic for you, maybe you should review your Perl learning material or program some exercises about how to convert between an array and a hash (and a hash and an array).

      For example, you might have this array:

      #!perl -w use strict; # Name Age Street my @user = (qw(John 42 Infinityway)); my %user = ...;

      How would you convert the data from @user (an array) to a hash (%user)?

      The names are easier for you to understand. your previous code used hashs.

      and what effective difference does it make, just how many rows are going to come back from that select? "use DBI;" probably cost more than hashref for this query.

Re^4: How to calculate the column and print it in pie chart format using perl?
by finddata (Sexton) on Mar 23, 2017 at 04:21 UTC
    The following error occurs: DBI fetchall_hashref: invalid number of arguments: got handle + 0, expected handle + between 1 and 1 Usage: $h->fetchall_hashref($key_field)

      Replace

      my $table = $sth->fetchall_hashref; for my $r (@$table) {
      with
      while(my $r=$sth->fetchrow_hashref ){

      So what did your boss say? Did you tell him yet that you cannot do this yourself and that you need to get others to do your assignments for you? He should be getting that idea by now anyway.

      edit killed erroneous semicolon

Re^4: How to calculate the column and print it in pie chart format using perl?
by finddata (Sexton) on Mar 23, 2017 at 05:04 UTC
    After changing it to while(my $r=$sth->fetchall_hashref;) what does the following line denotes: for my $r (@$table) { my $name='other'; for my $s (@sys){ if ($r->{queue_name}=~m/$s/i) {$name=$s; last;} }
    How the $table is used here without any pre declaration.

      Hi finddata,

      Some time ago, a fellow sent emails asking for help over and over. I mentioned a book to read. The Perl by Example by Ellie Quigley is a great resource in helping one master Perl with classroom-like instructions. This fellow did the very thing.

      Do not be overwhelm by the number of pages. Only the first 200 ~ 230 pages will fill your mind with a wonderful foundation regarding the Perl scripting language. Just think, you'd reach page 5, then onwards to page 10, and soon understand everything up through page 35. You'd soon reach page 140 and want to celebrate with the entire family and friends upon crossing the 200 mark.

      Visualize reaching this milestone. What a fantastic journey that might be.

      Regards, Mario

        Thank you for your suggestions.

      You dont follow directions well do you?

        Just am clarifying the things and its usage.How you used.