WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : How to create charts for php using Rchart
Categories : PHP, Java, JSP, Graphics, Charts and Graphs Update Picture
Jaume Sola
Date : May 19th 2003
Grade : 2 of 5 (graded 5 times)
Viewed : 17505
File : 3657.zip
Images : No Images for this code example.
Search : More code by Jaume Sola
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

The following example will create an area chart (it is very similar to the example Chart2.htm).

It will retrieve the data from an MSAccess database that contains a table called "salesMonth". This
table has three fields: "Products" (integer), "Services" (integer) and "salesMonth" (date), which
contains the sales for several months. The files are attached to this example for download.

The example will display the sales of the last 6 months. It will create a HTML page that contains
the applet. Most of the parameters of the applet are constant, however the date labels and the
sales data is retrieved from the DB.

This example was tested on windows. If you want to try to make it work on Unix or Linux platforms
you will need a way to access the mdb file. Try at : http://mdbtools.sourceforge.net/.

More information can be found at http://www.java4less.com (click on RChart)

<HTML>
<HEAD></HEAD>
<BODY>
<APPLET
CODEBASE = "."
CODE = "com.java4less.rchart.ChartApplet.class"
ARCHIVE= "rchart.jar"
NAME = "TestApplet"
WIDTH = 500 HEIGHT = 500 ALIGN = middle
>


<!-- **** VARIABLE DATA, use Php to retrieve series data values from database ****
-->

<?php
$labels
="";
$values2="";
$values1="";
$i=1;

/* connect to database
open db using a System ODBC data source called "Data" */
$odbcid = odbc_connect ("data", "", "", "");
/* get sales data, execute SQL*/
$resultid = odbc_exec ($odbcid, "Select * from SalesMonth Order by salesMonth DESC") ;


/* iterate on sales data, up to 6 rows */
while (($i <= 6) and (odbc_fetch_row($resultid))) {
/* concatenate | separator */
if ($i>1) {
$values1= "|" . $values1;
$values2= "|" . $values2;
$labels= "|" . $labels;
}

/* concatenate value */
$values1= odbc_result ($resultid, "Services") . $values1;
$values2= odbc_result ($resultid, "Product") . $values2;
$labels= odbc_result ($resultid, "salesMonth") . $labels;

$i=$i+1;
/* next record */
odbc_fetch_row($resultid);
}


/* echo values for serie 1 */
echo "<PARAM NAME = \"SERIE_DATA_1\" VALUE = \"";
echo
$values1;
echo
"\">";

/* echo values for serie 2 */
echo "<PARAM NAME = \"SERIE_DATA_2\" VALUE = \"";
echo
$values2;
echo
"\">";

/* echo values for labels */
echo "<PARAM NAME = \"XAXIS_LABELS\" VALUE = \"";
echo
$labels;
echo
"\">";

/* close result */
odbc_free_result($resultid);
/* close connection */
odbc_close($odbcid);

?>


<!-- **** CONSTANT DATA **** -->
<PARAM NAME = "TITLECHART" VALUE = "Sales 1999">
<PARAM NAME = "LEGEND" VALUE = "TRUE">
<PARAM NAME = "XLABEL" VALUE = "Month">
<PARAM NAME = "YLABEL" VALUE = "Million $">
<PARAM NAME = "SERIE_1" VALUE = "Services">
<PARAM NAME = "SERIE_2" VALUE = "Products">
<PARAM NAME = "SERIE_STYLE_1" VALUE = "0.2|0x663300|LINE">
<PARAM NAME = "SERIE_STYLE_2" VALUE = "0.2|0x99|LINE">
<PARAM NAME = "SERIE_FILL_1" VALUE = "RED">
<PARAM NAME = "SERIE_FILL_2" VALUE = "0x99cc">
<PARAM NAME = "SERIE_FONT_1" VALUE = "Arial|PLAIN|8">
<PARAM NAME = "SERIE_FONT_2" VALUE = "Arial|PLAIN|8">
<PARAM NAME = "SERIE_POINT_1" VALUE = "true">
<PARAM NAME = "SERIE_POINT_2" VALUE = "true">
<PARAM NAME = "SERIE_TYPE_1" VALUE = "LINE">
<PARAM NAME = "SERIE_TYPE_2" VALUE = "LINE">
<PARAM NAME = "CHART_BORDER" VALUE = "0.2|BLACK|LINE">
<PARAM NAME = "CHART_FILL" VALUE = "LIGHTGRAY">
<PARAM NAME = "BIG_TICK_INTERVALX" VALUE = "1">
<PARAM NAME = "BIG_TICK_INTERVALY" VALUE = "1">
<PARAM NAME = "YSCALE_MIN" VALUE = "0">
<PARAM NAME = "TICK_INTERVALY" VALUE = "100">
<PARAM NAME = "LEGEND_BORDER" VALUE = "0.2|BLACK|LINE">
<PARAM NAME = "LEGEND_FILL" VALUE = "WHITE">
<PARAM NAME = "XAXIS_TICKATBASE" VALUE = "true">
<PARAM NAME = "XAXIS_TICKATBASE" VALUE = "true">
<PARAM NAME = "BACK_IMAGE" VALUE = "back13.gif">
</APPLET>
</BODY>
</HTML>



You can also work with MySQL :
==============================

Steps:

1. Upload rchart.jar to your server
2. Execute the Mysql scripts to create the table in MySql
3. execute the php script.


SCRIPTS FOR MYSQL
CREATE TABLE j4l_example_SalesMonth (
   id int(11) DEFAULT '0' NOT NULL,
   salesMonth date DEFAULT '0000-00-00' NOT NULL,
   Product int(11) DEFAULT '0' NOT NULL,
   Services int(11) DEFAULT '0' NOT NULL,
   PRIMARY KEY (id)
);

#
# Dumping data for table 'j4l_example_SalesMonth'
#

INSERT INTO j4l_example_SalesMonth (id, salesMonth, Product, Services) VALUES ( '1', '2001-11-
20', '12', '32'); INSERT INTO j4l_example_SalesMonth (id, salesMonth, Product, Services) VALUES
( '2', '2001-12-20', '80', '140'); INSERT INTO j4l_example_SalesMonth (id, salesMonth, Product,
Services) VALUES ( '3', '2002-01-20', '300', '700'); INSERT INTO j4l_example_SalesMonth (id,
salesMonth, Product, Services) VALUES ( '4', '2002-02-20', '450', '600'); INSERT INTO
j4l_example_SalesMonth (id, salesMonth, Product, Services) VALUES ( '5', '2002-03-
20', '300', '760'); INSERT INTO j4l_example_SalesMonth (id, salesMonth, Product, Services) VALUES
( '6', '2002-04-20', '320', '930'); INSERT INTO j4l_example_SalesMonth (id, salesMonth, Product,
Services) VALUES ( '7', '2002-07-20', '420', '400');



PHP SCRIPT
<HTML>
<HEAD></HEAD>
<BODY>
<APPLET
CODEBASE = "."
CODE = "com.java4less.rchart.ChartApplet.class"
ARcHIVE = "rchart.jar"
NAME = "TestApplet"
WIDTH = 500 HEIGHT = 500 ALIGN = middle
>

<!-- **** VARIABLE DATA, use Php to retrieve series data values from database ****
-->

<?php
$labels
="";
$values2="";
$values1="";
$i=1;
$numrows=0;
$resultid=0;
$db=0;

/* connect to database */

/* connect to mysql */
$db = mysql_connect("localhost", "YOURUSER", "YOURPASSWORD") or die("Failed connection"); ;

/* select database*/
mysql_select_db("YOURDATABASE", $db);

/* get sales data, execute SQL*/
$resultid = mysql_query("Select salesMonth,Product,Services from j4l_example_SalesMonth Order by
salesMonth DESC"
) or die("Failed: sql");

/* iterate on sales data, up to 6 rows */
$numrows = mysql_num_rows($resultid);
while ((
$i <= 6) and ($i < $numrows)) {

$resrow=mysql_fetch_row($resultid);

/* concatenate | separator */
if ($i>1) {
$values1= "|" . $values1;
$values2= "|" . $values2;
$labels= "|" . $labels;
}

/* concatenate value */
$values1=$resrow[2] . $values1;
$values2= $resrow[1] . $values2;
$labels= $resrow[0] . $labels;

$i=$i+1;
/* next record */
}


/* echo values for serie 1 */
echo "<PARAM NAME = \"SERIE_DATA_1\" VALUE = \"";
echo
$values1;
echo
"\">";

/* echo values for serie 2 */
echo "<PARAM NAME = \"SERIE_DATA_2\" VALUE = \"";
echo
$values2;
echo
"\">";

/* echo values for labels */
echo "<PARAM NAME = \"XAXIS_LABELS\" VALUE = \"";
echo
$labels;
echo
"\">";

/* close connection */
mysql_close($db);


?>


<!-- **** CONSTANT DATA **** -->
<PARAM NAME = "TITLECHART" VALUE = "Sales 1999">
<PARAM NAME = "LEGEND" VALUE = "TRUE">
<PARAM NAME = "XLABEL" VALUE = "Month">
<PARAM NAME = "YLABEL" VALUE = "Million $">
<PARAM NAME = "SERIE_1" VALUE = "Services">
<PARAM NAME = "SERIE_2" VALUE = "Products">
<PARAM NAME = "SERIE_STYLE_1" VALUE = "0.2|0x663300|LINE">
<PARAM NAME = "SERIE_STYLE_2" VALUE = "0.2|0x99|LINE">
<PARAM NAME = "SERIE_FILL_1" VALUE = "RED">
<PARAM NAME = "SERIE_FILL_2" VALUE = "0x99cc">
<PARAM NAME = "SERIE_FONT_1" VALUE = "Arial|PLAIN|8">
<PARAM NAME = "SERIE_FONT_2" VALUE = "Arial|PLAIN|8">
<PARAM NAME = "SERIE_POINT_1" VALUE = "true">
<PARAM NAME = "SERIE_POINT_2" VALUE = "true">
<PARAM NAME = "SERIE_TYPE_1" VALUE = "LINE">
<PARAM NAME = "SERIE_TYPE_2" VALUE = "LINE">
<PARAM NAME = "CHART_BORDER" VALUE = "0.2|BLACK|LINE">
<PARAM NAME = "BIG_TICK_INTERVALX" VALUE = "1">
<PARAM NAME = "BIG_TICK_INTERVALY" VALUE = "1">
<PARAM NAME = "YSCALE_MIN" VALUE = "0">
<PARAM NAME = "TICK_INTERVALY" VALUE = "100">
<PARAM NAME = "LEGEND_BORDER" VALUE = "0.2|BLACK|LINE">
<PARAM NAME = "LEGEND_FILL" VALUE = "WHITE">
<PARAM NAME = "XAXIS_TICKATBASE" VALUE = "true">
<PARAM NAME = "XAXIS_TICKATBASE" VALUE = "true">
<PARAM NAME = "CHART_FILL" VALUE = "0xffcc00">
<PARAM NAME = "CHART_SHOW_POSITION" VALUE = "true">
</APPLET>
</BODY>
</HTML>


Here is a link for an example : http://www.jaagle.com/examples/rchart_example.php



HTML_Graphs provides a simple PHP interface for creating pure HTML charts.
Categories : Graphics, PHP, PHP Classes, Charts and Graphs
3dLib - a class for drawing in 3D space. Supported functions: Line, SetPixel, Polygon, FilledPolygon, etc. 3dChart() function has been added for one-call drawing of 3d charts. Support of mostly used 3d-transformations.
Categories : Graphics, Math., PHP Classes, PHP, Charts and Graphs
Display a bar chart based on random values.
Categories : Graphics, PHP, GD image library, Charts and Graphs
Annual Bar Chart
Categories : Graphics, PHP, Charts and Graphs
HTML_Graphs uses PHP to provide a consistent interface for creating HTML based charts. The user of the class sets up arrays that are passed to html_graph() which then takes care of all the messy HTML layout.
Categories : Graphics, Arrays, PHP, PHP Classes, Charts and Graphs
PHP interface class to the eBusiness Charts generatation remote service.
Categories : PHP, PHP Classes, Graphics, Charts and Graphs
a simple pie-chart in php3 (with gd)
Categories : PHP, Graphics, GD image library, Charts and Graphs
Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics, PHP, PHP Classes, GD image library, Charts and Graphs
PHPixel - output of 1 pixel transparent/colored gif for counters etc.
Categories : PHP, Graphics, HTML and PHP
PHP Image Validation Class - test if a specific file is of a certain image type without relying on the said file extension.
Categories : PHP, PHP Classes, Data Validation, Graphics, Beginner Guides
Using PHP im HTML image tags
Categories : PHP, HTML and PHP, Graphics, Beginner Guides
Audio-Enable Discussion Boards with this Web-page Audio Recorder / Player!
Categories : PHP Extensions, Java, PHP
Upload images restricted by pixel size (Picture width and Picture Height)
Categories : PHP, HTML and PHP, Graphics
Render TTF Text to PNG. Text message, font, size, rotation, padding, color, background, and transparency can all be defined via URL.
Categories : PHP, PHP Classes, Graphics
img_upload - array img_upload(string 'form field name', string 'image name', string 'destination'); Returns an array with 2 elements. Index 0 contains the string name of the image. Index 1 contains the string path to the image.
Categories : Graphics, PHP
 Sarah King wrote : 969
This is a good example but really it`s just promoting a tool you have to purchase before you can use the example. Stinks of spam!
 
 Boaz Yahav wrote : 970
I was thinking the same thing before i approved this example. I usually don`t approve exampled that promote any business but this one looks like something developers might use. After all, the examples here come to server as help to get things done so there is also an informative side to this example.

Lets wait and see what others think so i know what to do in the future.
 
 Nicolay Vasiliev wrote :972
It does nothing new in comparing of JpGraph http://www.aditus.nu/jpgraph/index.php