How to generata the data in graph???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
teckyan888
Forum Commoner
Posts: 40
Joined: Tue May 11, 2004 10:46 am

How to generata the data in graph???

Post by teckyan888 »

Anyone who know how to generate the data inside the database???
For example,1998 has 100 items,1999 has 120 items, 2000 has items...Then,i wan to calculate the total of the items for each year, then come out the graph by using the php code.......So,does anyone know how to do it???Thanks.... :)
swdev
Forum Commoner
Posts: 59
Joined: Mon Oct 25, 2004 8:04 am

Post by swdev »

Without knowing the structure of the table in the database that holds the information, i can't give you the exact code.

However, assuming that a column called my_item_name and once called my_year exists in the table called my_data, and the data looks something like

my_item_name my_year
item1 1998
item2 1998
item3 1999
item4 2000
item5 1999
...

then the SQL you would need is

Code: Select all

SELECT
  count(my_item_name) as total,
   my_year
FROM
  my_data
GROUP BY
  my_year
ORDER BY
  my_year ASC
;
As for graphing, I don't know. are you using a 3rd party graphing library?

Hope this helps
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Post by Calimero »

If the data is inside the db - and you know the SUM() just pass it as a variable, if not - use SUM() for integer values in fields, or COUNT() if you need number of fields that match the criteria

For graphing:

Use this (untested):

Code: Select all

<?php



for ( $i = 0; $i < $db_result_returned; $i++ )
{

echo "<img src='some_url'>";

}

// $db_result_returned - the SUM() or COUNT() result from the db for one year

// this image inside the for loop - create small rectangular image - color is for you to choose and save it somewhere. Just enter the right path inside the src="...." part.

?>
You should get horizontal bar chart/graph.

This'll get you started - develop the idea to a greater level ( and give me the better version :D )
teckyan888
Forum Commoner
Posts: 40
Joined: Tue May 11, 2004 10:46 am

Post by teckyan888 »

But the problem is, the database auto generating the total data, and the real data will be automatic show on the graph oh.then,make the comparison between year by year...Does the php support this such of function???
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

if you want to make dinamic graphs: http://www.aditus.nu/jpgraph/
teckyan888
Forum Commoner
Posts: 40
Joined: Tue May 11, 2004 10:46 am

Post by teckyan888 »

Thanks...But after i download the jpgraph-1.12.2, then,what should i do next??? Can u list down what i put inside my c drive???Should i put the specify file inside the system file folder??? How about the directory???
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

install it in your web root.. and open the /src/Examples in the web browser.
it not read de README file
teckyan888
Forum Commoner
Posts: 40
Joined: Tue May 11, 2004 10:46 am

Post by teckyan888 »

Sorry...i am newbie for php...Is it install at here:
C:\Program Files\Apache Group\Apache2\htdocs

Then, if the error message got show:

Code: Select all

<?php
JpGraph Error: No path specified for CACHE_DIR. Please specify a path for that DEFINE in jpgraph.php

?>
So,where should i change the DIR and change to which directory???anywho who know it??thanks...
Post Reply