PHP Graph dengan JPGraph Chart

Membuat chart dengan data yang ada pada database MySQL menggunakan class JPGraph, berikut chart bar “Resource by Customer” dengan background image, warna bar dan value data dari database…

untuk melihat sampel-sampel chart JPGraph silahkan download source dan dokumentasinya http://www.aditus.nu/jpgraph/documentation.php.

<?php
include “../db_connect.php”;
$result = mysql_query(‘select c.company_color,count(distinct pc.contact_id),c.company_short_name from projects p,companies c,project_contacts pc where p.project_status=3 and c.company_id=p.project_company and pc.project_id=p.project_id group by p.project_company’);

$x = 0;
while ($row = mysql_fetch_array($result)) {
if($x == 0){
$com .=$row[2];
$jml .=$row[1];
$cco .=$row[0].’@0.4′;
}else{
$com .= ‘,’.$row[2];
$jml .= ‘,’.$row[1];
$cco .= ‘,’.$row[0].’@0.4′;
}
$x++;
}

//masukan $jml_pro kedalam array
$datay1 = explode(‘,’, $jml);
$color = explode(‘,’, $cco);
$compn = explode(‘,’, $com);

include (“../jpgraph.php”);
include (“../jpgraph_bar.php”);

// Create the basic graph
$graph = new Graph(500,350,’auto’);�
$graph->SetScale(“textlin”);
$graph->img->SetMargin(40,80,30,40);

// Adjust the position of the legend box
$graph->legend->Pos(0.02,0.10);

// Adjust the color for theshadow of the legend
$graph->legend->SetShadow(‘darkgray@0.5’);
$graph->legend->SetFillColor(‘lightblue@0.3’);

// Get localised version of the month names
$graph->xaxis->SetTickLabels($compn);

// Set a 247 building (in segitigaemas) image
$graph->SetBackgroundImage(‘247.PNG’,BGIMG_COPY);

// Set axis titles and fonts
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetColor(‘white’);

$graph->xaxis->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->SetColor(‘white’);

$graph->yaxis->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->SetColor(‘white’);

$graph->ygrid->SetColor(‘white@0.5’);

// Setup graph title
$graph->title->Set(‘Resource by Customer’);

// Some extra margin (from the top)
$graph->title->SetMargin(3);
$graph->title->SetFont(FF_ARIAL,FS_NORMAL,12);

// Create the three var series we will combine
$bplot1 = new BarPlot($datay1);

// Setup the colors with 40% transparency (alpha channel)
$bplot1->SetFillColor($color);
$bplot1->value->Show();
$bplot1->value->SetFormat(‘%d’);
$bplot1->value->SetFont(FF_FONT2);
$bplot1->value->SetColor(‘#ffffff’);

// Setup each bar with a shadow of 50% transparency
$bplot1->SetShadow(‘black@0.4’);
$gbarplot = new GroupBarPlot(array($bplot1));
$gbarplot->SetWidth(0.6);
$graph->Add($gbarplot);

$graph->Stroke();
?>

berikut layout hasil script diatas:

Advertisements

About davidand

Hi, welcome to my blogs. My name is David Andriansyah. I am currently working as an independent Cognos Business Intelligence consultant, and I also as Freelance Web Developer. View all posts by davidand

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: