473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to create pie chart

my requirement is
1.To create a pie chart
2.the value will be updating from the database

How can i do this ?
Jul 10 '07 #1
8 9865
nitinpatel1117
111 100+
You can use a PHP extension (GD library) to create images.

see this for more info:
http://uk3.php.net/gd

once you get the GD library configured properly you can either do the coding yourselve, or do a search on google for frree libaries that draw graphs for you. NOTE: these libraries will still need the GD extension on your server.
Jul 10 '07 #2
please help me.gd library is installed in my server.i need some sample code
Jul 10 '07 #3
nitinpatel1117
111 100+
look at this library, its what i used a while back, its good for creating simple graphs .

Has good documentation with sample code.

Also i think it's opensource

http://sourceforge.net/projects/phplot/
Jul 10 '07 #4
pbmods
5,821 Expert 4TB
Heya, sumaabey.

The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. You have not asked a question. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

Then when you are ready post a new question in this thread.

MODERATOR

Also, take a look at this thread. Note how the other poster offered to try it first.
Jul 10 '07 #5
http://192.168.1.60/dlf/
Jul 11 '07 #6
http://192.168.1.60/dlf/.
Jul 11 '07 #7
thanks everybody i solved the problem
Jul 11 '07 #8
<?php
/********************************
2D Pie Chart Version 1.0
Programer: Xiao Bin Zhao
E-mail: love1001_98@yahoo.com
Date: 03/31/2001
All Rights Reserved 2001.
********************************/

/*************Configuration Starts Here******************/

$chartTitle = "Percentage of Products in Database"; //pie chart name

/*************************End********************** ******/

/*****************For Programers Only********************/
$imageWidth = 600; //image width
$imageHeight = 400; //image height
$diameter = 250; //pie diameter
$centerX = 225; //pie center pixels x
$centerY = 225; //pie center pixels y
$labelWidth = 10; //label width, no need to change
/*************************End********************** ******/

//db connection info.
$dbuser = 'db';

$dbhost = 'localhost';

$dbpass = '';

$dbname = 'rhishabh';

$mysql_link = mysql_connect($dbhost,$dbuser,$dbpass) or die ("Could not connect"); //connect to db

mysql_select_db ($dbname) or die ("DB select failed"); //select db

$query1 = "select productname, count(*) as groupcount from product group by productname"; //get product count by groups of products

$query2 = "select count(*) as countammount from product"; //get the ammount of products in the db

$result1 = mysql_db_query($dbname,$query1); //queryresult1

$result2 = mysql_db_query($dbname,$query2); //queryresult2

$result3 = mysql_db_query($dbname,$query1); //queryresult3

$num_products = mysql_num_rows($result1); //count number of products

while ($row = mysql_fetch_assoc ($result2)) //put total ammount of products in db from query in a var
{
$dataTotal = $row[countammount];
}

function circlePoint( $deg, $dia )
{
$x = cos( deg2rad( $deg ) ) * ( $dia / 2 );
$y = sin( deg2rad( $deg ) ) * ( $dia / 2 );
return array( $x, $y );
}

$im = ImageCreate( $imageWidth, $imageHeight ); //make image area

//color array for chart. addmore colors if you have more data than colors below.
$color[] = ImageColorAllocate( $im, 255, 0, 0 ); //red
$color[] = ImageColorAllocate( $im, 255, 204, 0 );//yellow
$color[] = ImageColorAllocate( $im, 153, 204, 0 );//green
$color[] = ImageColorAllocate( $im, 153, 51, 255 );//purple
$color[] = ImageColorAllocate( $im, 0, 128, 255 );//blue
$color[] = ImageColorAllocate( $im, 255, 0, 128 );//pink
$color[] = ImageColorAllocate( $im, 153, 51, 255 );//purple
$color[] = ImageColorAllocate( $im, 192, 192, 192 );//grey
$color[] = ImageColorAllocate( $im, 204, 204, 0 );
$color[] = ImageColorAllocate( $im, 64, 128, 128 );
$color[] = ImageColorAllocate( $im, 204, 102, 153 );
$white = ImageColorAllocate( $im, 255, 255, 255 );
$black = ImageColorAllocate( $im, 0, 0, 0 );
$grey = ImageColorAllocate( $im, 215, 215, 215 );

ImageFill( $im, 0, 0, $white ); //make image background

$degree = 0;

/**********************************
make the pie chart with percentages
**********************************/

$i=-1; //set color array counter

while ($row = mysql_fetch_assoc ($result1))
{

$i < sizeof( $row ); $i++; //counter for color array

$startDegree = round( $degree );
$degree += ( $row[groupcount] / $dataTotal ) * 360;
$endDegree = round( $degree );

$currentColor = $color[ $i % ( count( $color ) ) ];

ImageArc( $im, $centerX, $centerY, $diameter, $diameter, $startDegree, $endDegree, $currentColor );

list( $arcX, $arcY ) = circlePoint( $startDegree, $diameter );
ImageLine( $im, $centerX, $centerY, floor( $centerX + $arcX ), floor( $centerY + $arcY ), $currentColor );

list( $arcX, $arcY ) = circlePoint( $endDegree, $diameter );
ImageLine( $im, $centerX, $centerY, ceil( $centerX + $arcX ), ceil( $centerY + $arcY ), $currentColor );

$midPoint = round( ( ( $endDegree - $startDegree ) / 2 ) + $startDegree );
list( $arcX, $arcY ) = circlePoint( $midPoint, $diameter / 1.5 );
ImageFillToBorder( $im, floor( $centerX + $arcX ), floor( $centerY + $arcY ), $currentColor, $currentColor );
//joe: i added -6 to center %'s better
ImageString( $im, 2, floor( $centerX + $arcX - 6 ), floor( $centerY + $arcY - 6 ), intval( round( $row[groupcount] / $dataTotal * 100 ) ) . "%", $white );

}

/**********************************
setup for the menu and print title
**********************************/

$labelX = $centerX + $diameter / 2 + 10;
$labelY = $centerY - $diameter / 4;
$titleX = $labelX - $diameter / 4;
$titleY = $centerY - $diameter / 2;
//ImageString( $im, 3, $titleX + 1, $titleY + 1, $chartTitle, $grey );
ImageString( $im, 3, $titleX, $titleY, $chartTitle, $black ); //print chart title
ImageString( $im, 1, $labelX, $titleY + 14, date( "Y-m-d H:i:sa" ), $black ); //print date

/**********************************
make the menu,lables,totals
**********************************/

$i=-1; //set color array counter

while ($row1 = mysql_fetch_assoc ($result3))
{

$i < sizeof( $row1 ); $i++; //counter for color array

$currentColor = $color[ $i % ( count( $color ) ) ];
ImageRectangle( $im, $labelX, $labelY, $labelX + $labelWidth, $labelY + $labelWidth, $black );
ImageFilledRectangle( $im, $labelX + 1, $labelY + 1, $labelX + $labelWidth, $labelY + $labelWidth, $currentColor );
ImageString( $im, 2, $labelX + $labelWidth + 5, $labelY, $row1[productname], $black );
//ImageString( $im, 2, $labelX + $labelWidth + 60, $labelY, $row1[groupcount], $black );
$labelY += $labelWidth + 2;
}

/**********************************
make the total
**********************************/

ImageString( $im, 3, $labelX, $labelY, "Total:", $black );
ImageString( $im, 3, $labelX + $labelWidth + 60, $labelY, $dataTotal, $black );
//ImageString( $im, 2, $labelX, $labelY + 15, $logo, $black );

Header( "Content-type: image/jpeg" ); //output image
Imagejpeg( $im );
ImageDestroy( $im ); //remove image from memory
?>
Jul 11 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Moth | last post by:
I have a PlotPanel class that extends JPanel which I have used previously to display charts in swing guis. I now want to display a graph in a jsp page so I was going to generate the graph and then...
1
by: Mike John | last post by:
I am trying to create a bar chart where I control the x and the y axis: X values: 5 45 20 Y Values: 1
0
by: Don Wash | last post by:
Hi There! I'm using bulit-in CrystalReport that comes with VS.NET 2003 to create reports for use it ASP.NET. How do I configure a graph in the Report (*.rpt file) so that I can have a...
0
by: pmclinn | last post by:
The code below takes the data from the S column and grabs all the data and graphs it. The problem is this example grabs 500 cells worth of data and some of these cells = nothing. How do I rescope...
6
by: twins | last post by:
Please let me know the easiest method to create a JPEG/GIF bar chart from PHP. I have found solutions that allow creation of swf/flash charts but I need a jpeg/jpg/gif bar chart.
0
by: Richie | last post by:
Hi All, I have a Survey report with numerous questions and subquestions. I am trying to create a chart for every question, and I am using a chart wizard for that. I am picking up the required...
2
by: Geoff Cox | last post by:
Hello, I have a database for subscriptions to a web site which has the date on which each application to join was made etc etc. Can I easily create a chart of the number of people subscribing...
1
by: vijay | last post by:
HI ALL, How to create excel chart programatically using C#.net 2005. I have created an excel file by using Gembox.Spreadsheet component.Now i want to add excel Chart to this...
1
by: phazawhy | last post by:
we have this requirement in school that we have to create a program that will able to solve the cpu scheduling (first come first serve, 1st job done and we need it to gant chart it). please teach me...
5
by: CoreyReynolds | last post by:
Hello all, I have some VB code that spits an Access query out into Excel and attempts to create a chart from it. The problem is it spits it into a format that Excel can't really eloquently make a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.