Source Code of: jpgraph_cdinterest.php
Date Last Modified: May 02, 2009 - 01:59:24 AM
Size: 3 KB  |  109 lines  |  3,045 characters
<?php
error_reporting
(E_ALL);



require(
"../lib/jpgraph/src/jpgraph.php");
require(
"../lib/jpgraph/src/jpgraph_line.php");

// months corresponding to the interests below
$months = Array('Apr05','May','Jun',
    
'Jul05','Aug','Sep','Oct05','Nov','Dec','Jan06','Feb','Mar','Apr06','May','Jun');
// interest data for 5 year cd
$interest_5yrcd = Array(8.6910.019.7310.0910.139.85,10.21,9.92,10.29,10.33,9.37,10.41,10.12,10.50,10.20);
// interest data for 15 month cd
$interest_15mocd = Array(12.1513.9913.5814.0714.1213.70,14.20,13.79,14.29,14.33,12.99,14.42,14.00,14.51,14.08);
// interest data for total interest of all cds
$interest_total = Array();

// calculate month totals
// cannot assume equal array sizes, but can assume count(5yr) > count(15mo)
$monthcount count($months);
for (
$i=0$i<$monthcount$i++)
{
    
// use zero if missing array data
    
$a $interest_15mocd[$i] ? $interest_15mocd[$i] : 0;
    
$b $interest_5yrcd[$i] ? $interest_5yrcd[$i] : 0;
    
$interest_total[] = $a $b;
// end for


// Setup the graph
$graph = new Graph(900,500);
$graph->SetMarginColor('white');
$graph->SetScale("textlin");
$graph->SetFrame(false);
$graph->SetMargin(30,180,30,50);


$graph->title->Set('Monthly Interest of 2 CDs (Filled Y-grid)');
$graph->title->SetAlign('left');


$graph->yaxis->HideZeroLabel();
$graph->ygrid->SetFill(true,'#EFEFEF@0.5','#BBCCFF@0.5');
$graph->xgrid->Show();

$graph->xaxis->SetTickLabels($months);

// Create the first line
$p1 = new LinePlot($interest_15mocd);
$p1->SetColor("navy");
$p1->SetLegend('15mo CD');
$p1->value->show();
$p1->value->HideZero();
$p1->value->SetColor('darkred');
$p1->value->SetFont(FF_FONT1,FS_BOLD);
$p1->value->SetFormat('$%01.2f');
$p1->value->SetAlign('left');
$p1->SetWeight(2);
$graph->Add($p1);

// Create the second line
$p2 = new LinePlot($interest_5yrcd);
$p2->SetColor("red");
$p2->SetLegend('5yr CD');
$p2->value->show();
$p2->value->HideZero();
$p2->value->SetColor('darkred');
$p2->value->SetFont(FF_FONT1,FS_BOLD);
$p2->value->SetFormat('$%01.2f');
$p2->value->SetAlign('left');
$p2->SetWeight(2);
$graph->Add($p2);

// Create the third line, an accumulation plot
$p3 = new LinePlot$interest_total );
$p3->SetColor("orange");
$p3->SetLegend('Total');
$p3->value->show();
$p3->value->HideZero();
$p3->value->SetColor('darkred');
$p3->value->SetFont(FF_FONT1,FS_BOLD);
$p3->value->SetFormat('$%01.2f');
$p3->value->SetAlign('left');
$p3->SetWeight(3);
$graph->Add($p3);

// set style of legend
$graph->legend->SetShadow('gray@0.4',5);
$graph->legend->SetPos(0.1,0.1,'right','top');

// output interest stats
$t1 = new Text(
"Interest
15mo Life: $"
number_format(array_sum($interest_15mocd), 2'.''') ."
5yr Life:  $"
number_format(array_sum($interest_5yrcd), 2'.''') ."
Total:     $"
number_format(array_sum($interest_total), 2'.'''));
$t1->Pos(0.70,0.75);
$t1->SetOrientation("h");
$t1->SetFont(FF_FONT1,FS_NORMAL);
$t1->SetBox("white","black",'gray');
$t1->SetColor("black");
$graph->AddText($t1);

// output graph
$graph->Stroke();


?>

A Derivative Work of: PHP Source Code Utility - Version 1.0.0 Copyright © 0php.com 2002.