in reply to Issues graphing multiple data sets on the same graph in GD::Graph

Update number two: I've created a similar solution that also *almost* works, but still only outputs a single line for the graph. If anyone has any idea, it'd be a lifesaver, for sure.
use DBI; use Class::Date qw(:errors date localdate gmdate now -DateParse -EnvC) +; use GD::Graph::lines; use Net::SMTP; #Change our date format since we don't care about times for these repo +rts. $Class::Date::DATE_FORMAT="%Y-%m-%d"; #Select our currently used Database $dbh = DBI->connect(); #prepare our sql statement 1 $sth1 = $dbh->prepare("SELECT GroupName, Members, NotifyTo FROM [Group +] "); $sth1->execute(); while (@row = $sth1->fetchrow_array) { $Group = @row[0]; @user = split (/\,/, @row[1]); #print "@user\n"; $userlist = ""; $userlist2 = ""; $x = 0; foreach $username (@user) { @date = ""; @totals = ""; $sth2 = $dbh->prepare("SELECT UserID, Name FROM [User] WHERE UserID = '$username'"); $sth2->execute(); while (@row1 = $sth2->fetchrow_array) { $longname = @row1[1]; $userlist .= "\[$longname\], "; $x++; } $userlist2 = substr($userlist, 0 ,-2); #print "$userlist2\n"; $sth3 = $dbh->prepare("SELECT Date, $userlist2 FROM [TicketSta +tus] WHERE Field LIKE 'Status' ORDER BY Date"); $sth3->execute(); while (@row2 = $sth3->fetchrow_array) { $date = date @row2[0]; push (@date, $date); $totals[$x] = @row2[$x]; #print "@row[0] X: $x $date: $totals[$x] \n"; push (@totals, $totals[$x]); #print "$date: @row[0] @totals\n"; } print "$group X $x $date: @totals\n\n"; } @data = ( [@date], [@totals] ); $graph1 = GD::Graph::lines->new(1024, 768); $graph1->set( x_label => 'Date', y_label => '% Closed', title => "$Group Vulnerability Tickets Closed" +, y_max_value => 100, y_tick_number => 10, x_label_skip => 7 ) or die $graph->error; $graph1->set( dclrs => [ qw(black dblue gold dgreen dred d +purple lorange dpink marine cyan dbrown lgray lblue lyellow dyellow l +green lred lpurple pink ) ] ); $graph1->set( line_types => [1, 3] ); $graph1->set_legend($userlist2); my $gd = $graph1->plot(\@data) or die $graph1->error; open (IMG, ">./$Group-test.jpg"); binmode IMG; print IMG $gd->png; close IMG; }
  • Comment on Re: Issues graphing multiple data sets on the same graph in GD::Graph
  • Download Code

Replies are listed 'Best First'.
Re^2: Issues graphing multiple data sets on the same graph in GD::Graph
by zentara (Cardinal) on Nov 13, 2007 at 13:43 UTC
    If anyone has any idea.......

    If you only see one data set, it is most likely that you are missing the x-axis data. If you go look at the example I posted previously, the @data contains 3 array references. The first is the x-axis data, the following two are the actual plot data. So you are missing an arrayref somewhere. Sorry thats all I can see, because your code is not runnable by me, to test.

    @date = ""; @totals = ""; ..... ........ @data = ( [@date], # this is the x-axis data [@totals], # first plot [@totals1] # this gives the second plot );

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      Thanks for all the help. That's the big issue with running a program like this-I am a bit on my own with it. All your attempts certainly have been appreciated, though.