Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GD::Graph , help sub grouping records needed

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
hello,

I'm tying to build a graph that has 3 graphs per data set as well as the graphs having 3 sub groups which I want indicating via a stacked graph, so you get the following type graph. (image example attached)

list of advisers, showing all Mortgage,Inusrance,Loan business they have done, but for each of these case types, they have a status code within 'SUB' , 'COMP' , 'NPW'

So I would like each group (Mort,Ins,Loan) , to be displayed as a stacked bar colour coded and showing values for how many Sub,Comp & NPW's make up each Case Type total.

I've got the following code, but it isn't yielding correct results.

I'm trying to make each array index value passed to the graph module being an array itself holding the 3 vaues for Sub,Comp,NPW

It's not erroring but the graph is gobbledygook, I know I'm also failing to provide the 'legend' for the sub group, but can't work out how I would provide this.

Is what i'm tying to do even possible?

Code:
use CGI ':standard';
use GD::Graph::bars;
use strict;

    my $graph = GD::Graph::bars->new(900, 400);

    my @dets = &set_where;

    my $where = $dets[0];
    my $title = $dets[1];

    my @rs = &getSQL("Business_Register LEFT OUTER JOIN Members ON Business_Register.Adv_MemNo = Members.ID","Adv_MemNo,FirstName,LastName,Rec_Type,Status","$where AND Ins_Lnk is null","Adv_MemNo DESC");

    if(!@rs){
        &nodata;
        exit();
    }

    my $comp = &cntSQL("Business_Register","$where AND Ins_Lnk is null AND Status='COMP'");
    my $mort = &cntSQL("Business_Register","$where AND Ins_Lnk is null AND Rec_Type='MORT'");
    my $subs = &cntSQL("Business_Register","$where AND Ins_Lnk is null AND Status='SUB'");
    my $ins = &cntSQL("Business_Register","$where AND Ins_Lnk is null AND Rec_Type='INS'");
    my $npw = &cntSQL("Business_Register","$where AND Ins_Lnk is null AND Status='NPW'");
    my $loan = &cntSQL("Business_Register","$where AND Ins_Lnk is null AND Rec_Type='LOAN'");

    my $tot = $loan+$mort+$ins;

    my $loop = -1;
    my (@advisers,@myadvisers);
    my ($adviser);

    for(@rs){       
        my $name = "$_->{'FirstName'} $_->{'LastName'}";
        if($adviser ne $name){
                $loop++;
                $advisers[$loop] = {name => "$name"};
                $advisers[$loop]->{'M_Submissions'}=0;
                $advisers[$loop]->{'M_Completions'}=0;
                $advisers[$loop]->{'M_Not Proceeding With'}=0;
                $advisers[$loop]->{'L_Submissions'}=0;
                $advisers[$loop]->{'L_Completions'}=0;
                $advisers[$loop]->{'L_Not Proceeding With'}=0;
                $advisers[$loop]->{'I_Submissions'}=0;
                $advisers[$loop]->{'I_Completions'}=0;
                $advisers[$loop]->{'I_Not Proceeding With'}=0;
                $adviser = $name;
                push @myadvisers, $name;
        }      
      
        if($_->{'Status'} eq "SUB" && $_->{Rec_Type} eq "MORT"){
            $advisers[$loop]->{'M_Submissions'}++;
        }
        if($_->{'Status'} eq "SUB" && $_->{Rec_Type} eq "INS"){
            $advisers[$loop]->{'I_Submissions'}++;
        }
        if($_->{'Status'} eq "SUB" && $_->{Rec_Type} eq "LOAN"){
            $advisers[$loop]->{'L_Submissions'}++;
        }

        if($_->{'Status'} eq "COMP"  && $_->{Rec_Type} eq "MORT"){
            $advisers[$loop]->{'M_Completions'}++;
        }
        if($_->{'Status'} eq "COMP"  && $_->{Rec_Type} eq "INS"){
            $advisers[$loop]->{'I_Completions'}++;
        }
        if($_->{'Status'} eq "COMP"  && $_->{Rec_Type} eq "LOAN"){
            $advisers[$loop]->{'L_Completions'}++;
        }

        if($_->{'Status'} eq "NPW" && $_->{Rec_Type} eq "MORT"){
            $advisers[$loop]->{'M_Not Proceeding With'}++;
        }
        if($_->{'Status'} eq "NPW" && $_->{Rec_Type} eq "LOAN"){
            $advisers[$loop]->{'L_Not Proceeding With'}++;
        }
        if($_->{'Status'} eq "NPW" && $_->{Rec_Type} eq "INS"){
            $advisers[$loop]->{'I_Not Proceeding With'}++;
        }
       
        $advisers[$loop]->{'Cnt'}++;
    }

    my(@mort,@loan,@ins);    
    for(@advisers){
        push @mort,[$_->{'M_Submissions'},$_->{'M_Completions'},$_->{'M_Not Proceeding With'}];
        push @loan,[$_->{'L_Submissions'},$_->{'L_Completions'},$_->{'L_Not Proceeding With'}];
        push @ins,[$_->{'I_Submissions'},$_->{'I_Completions'},$_->{'I_Not Proceeding With'}];
    }

    push my @data, \@myadvisers;
    push @data, @mort;
    push @data, @ins;
    push @data, @loan;
    

    $graph->set(
        title       => $title,
        x_label     => 'Business Type',
        y_label     => 'Business Volume (' . $tot . ')',
        show_values => 1,
        long_ticks  => 0,
        #dclrs       => ['#FFFF00', '#00FF00', '#FF0000'],
        x_labels_vertical => 1,
        x_label_position => .5,
        axislabelclr => 'black',
        legendclr => 'black',
        axis_space => 16,
        bar_spacing => 10,
        bargroup_spacing => 20,
        bar_width => 60,

        cumulate => 0,
        #transparent => 1,
        shadow_depth => 4, 

    ) or warn $graph->error;

    $graph->set_y_label_font('/websites//cgi-bin/trebuc.ttf',14);
    $graph->set_x_label_font('/websites//cgi-bin/trebuc.ttf',14);
    $graph->set_x_axis_font('/websites//cgi-bin/trebuc.ttf',10); 
    $graph->set_y_axis_font('/websites//cgi-bin/trebuc.ttf',10); 
    $graph->set_title_font('/websites//cgi-bin/trebuc.ttf',14);  
    $graph->set_legend_font('/websites//cgi-bin/trebuc.ttf',12); 
    $graph->set_legend('Mortgage (' . $mort . ')','Insurance (' . $ins . ')','Loan (' . $loan . ')');
    $graph->set_values_font('/websites//cgi-bin/trebuc.ttf',8); 

    print "Content-type: image/png\n\n";
    print $graph->plot(\@data)->png or die $graph->error;

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
It's ok I haved decided to ditch the GD::Graph module and now use FusionChartsFree flash plugin instead.

Not sure if it will still do what I want but the graphs it produces are far nicer than GD:Graph

plus I can no longer find the GD:Graph website, which used to be a great resource for this module.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top