Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by huck (Prior)
on Mar 22, 2017 at 05:27 UTC ( [id://1185404]=note: print w/replies, xml ) Need Help??


in reply to How to calculate the column and print it in pie chart format using perl?

It looks like you are writing commands that another program will use to create the pie chart. What program is that?

How are you accessing the mysql database from perl and storing the data you get back from the select statement?

  • Comment on Re: How to calculate the column and print it in pie chart format using perl?

Replies are listed 'Best First'.
Re^2: How to calculate the column and print it in pie chart format using perl?
by finddata (Sexton) on Mar 22, 2017 at 05:30 UTC
    am using perl cgi script.Here i had added the part of the code.
      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 distinct * from summary order by time desc ;"; ; my $sth = $DBH->prepare( $stmt ); $sth->execute() or print "Could not in7sert_overall_summarydata"; print "<script language=\"javascript\" type=\"text/javascript\"> \ +n"; print "\$(document).ready(function(){ \n"; %TABLE_DATA =(); print "var data_running=[[\"Adice \($TABLE_DATA{1}{'ENTRY'}\)\",$TABLE +_DATA{5}{'ENTRY'}],\ [\"Incisive \($TABLE_DATA{1}{'ENTRY'}\)\",$TABLE_ +DATA{5}{'ENTRY'}],\ [\"Vcs \($TABLE_DATA{1}{'ENTRY'}\)\",$TABLE_DATA{ +5}{'ENTRY'}], \n"; print "var data_pending=[[\"Adice \($TABLE_DATA{1}{'ENT +RY'}\)\",$TABLE_DATA{4}{'ENTRY'}],\ [\"Incisive \($TABLE_DATA{1}{'ENTRY'}\)\",$TABLE_ +DATA{4}{'ENTRY'}],\ [\"Vcs \($TABLE_DATA{1}{'ENTRY'}\)\",$TABLE_DATA{ +4}{'ENTRY'}],\n"; + [download] print " \n + pieChart(\"placeholder39\",data_running,{title:\"<b><center>Jobs Run +ning</center></b>\"});\n"; print " \n pieChart(\"placeholder41\",data_pending,{title:\"<b>< +center>Jobs Pending</center></b>\"});\n"; [download] print " \n pieChart(\"placeholder30\",data_machine,{title:\"<b>< +center>Machine Status<center></b>\"});"; print " \n pieChart(\"placeholder29\",data_cpu,{title:\"<b><cent +er>CPU Slots</center></b>\"});\n"; print " \n pieChart(\"placeholder39\",data_running,{title:\"<b>< +center>Jobs Running</center></b>\"});\n"; print " \n pieChart(\"placeholder41\",data_pending,{title:\"<b>< +center>Jobs Pending</center></b>\"});\n"; print "});"; print "</script>"; }

        You didn not answer the question: Which javascript package do you expect to make the pie chart for you?

        You seem to be missing anything that gets the data, $sth->execute() does not return any data. you need something like my $table = $sth->fetchall_hashref; to actualy get the data. That returns an array reference such that $table->[0] has the first row of data and $table->[0]{queue_name} has the value of the queue_name column in the first row. That in no way matches your attempts to use something like $TABLE_DATA{1}{'ENTRY'} as a variable name where 1 is taken as a key to the hash %TABLE_DATA and ENTRY is taken as key to the hash %{$TABLE_DATA{1}}.

        This should be easy, first, rename the subroutine print_overall_summary to print_pie_chart and then just implement the new subroutine.

        Oh, by the way ... did you check the CPAN? SVG::TT::Graph::Pie.

Re^2: How to calculate the column and print it in pie chart format using perl?
by finddata (Sexton) on Mar 22, 2017 at 06:09 UTC
    <head> <link rel="stylesheet" type="text/css" href="../lib/DataTables/med +ia/css/jquery.dataTables.css"> <link rel="stylesheet" type="text/css" href="../lib/Dat +aTables/examples/resources/syntax/shCore.css"> <script language="javascript" type="text/javascript" src="../l +ib/flot/current/jquery.js"></script> <script type="text/javascript" language="javascript" src="../l +ib/DataTables/media/js/jquery.dataTables.js"></script> <script type="text/javascript" language="javascript" src="../l +ib/DataTables/examples/resources/syntax/shCore.js"></script> <script type="text/javascript" language="javascript" src="../l +ib/DataTables/examples/resources/demo.js"></script> <script type="text/javascript" language="javascript" src="../l +ib/DataTables/extensions/ColVis/js/dataTables.colVis.js"></script> + <script type="text/javascript" language="javascript" src="../l +ib/DataTables/extensions/TableTools/js/dataTables.tableTools.js"></sc +ript> <script language="javascript" type="text/javascript" src=" . +./lib/flot/current/jquery.flot.js"></script> <!-- <script language="javascript" type="text/javascript" src= +" ../lib/flot/current/demo_table.css"></script> --> <script language="javascript" type="text/javascript" +src=" ../lib/new_style.css"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.flot.categories.js"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.flot.pie.js"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.flot.stack.js"></script> <script language="javascript" type="text/javascript" src=" ../ +lib/flot/current/jquery.flot.axislabels.js"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.flot.resize.js"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.flot.tooltip.js"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.flot.navigate.js "></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/date.js"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.dataTables.min.js"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.validate.js"></script> <script language="javascript" type="text/javascript" src="../l +ib/flot_test.js"></script> <script language="javascript" type="text/javascript" src="../l +ib/flot.js"></script> <link rel="stylesheet" type="text/css" href="../lib/stylesheet.css +"> <link rel="stylesheet" type="text/css" href="../lib/DataTables +/media/css/jquery.dataTables.css"> <link rel="stylesheet" type="text/css" href="../lib/DataTables/exa +mples/resources/syntax/shCore.css"> <!-- <link rel="stylesheet" type="text/css" href=" ../lib/mysty +le.css">--> <!-- <link rel="stylesheet" type="text/css" href="../lib/DataTa +bles/extensions/ColVis/css/dataTables.colVis.css"> <link rel="stylesheet" type="text/css" href="../lib/DataTables +/extensions/TableTools/css/dataTables.tableTools.css"> --> <!-- <link rel="stylesheet" type="text/css" href="../etc/css/st +yles.css" /> --> <script type="text/javascript" language="javascript" src="../l +ib/DataTables/examples/resources/syntax/shCore.js"></script> <script type="text/javascript" language="javascript" src="../l +ib/DataTables/examples/resources/demo.js"></script> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <META HTTP-EQUIV="Expires" CONTENT="-1"> </head>

      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

        why you had used hashref is it not possible with arrayref?
        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)
        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1185404]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-25 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found