Using PHP, MySQL and JpGraph to Create Dynamic Graphs

Slides:



Advertisements
Similar presentations
IEXL -- Green is great but sometimes only color will do … Simplify creation of spreadsheets, directly from the Iseries Keep your cost down Leverage your.
Advertisements

PHP Sample Application Simple graphics and database.
Access - Project 1 l What Is a Database? –A Collection of Data –Organized in a manner to allow: »Access »Retrieval »Use of That Data.
CIS101 Introduction to Computing Review of Charts Excel Project Two.
McGraw-Hill Technology Education © 2004 by the McGraw-Hill Companies, Inc. All rights reserved. Office Excel 2003 Lab 2 Charting Worksheet Data.
Graphing With Excel Presented by Frank H. Osborne, Ph. D. © 2008 ID 2950 Technology and the Young Child.
Graphing. The Important Elements of a Graph  Horizontal Axis (X-Axis)  Represents the passage of time and the numerical value of behavior.  The Independent.
ESAP T T02-01 Quick Graphs (Line Plot, Bar Graph, Pie Chart) Purpose Allows the analyst to create line plots, bar graphs and pie charts from data,
Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 12 Spreadsheets and Business Graphics: Facts and Figures.
How to Make a Bar/Line Graph
How To Make Graphs in Microsoft Excel Outline Making Bar Graphs Making Scatter Plots – 1 series Making Scatter Plots – Multiple Series.
1 Chapter 3: Getting Started with Tasks 3.1 Introduction to Tasks and Wizards 3.2 Creating a Frequency Report 3.3 Generating HTML, PDF, and RTF Output.
Exporting Data and Creating Financial Reports with Excel and Crystal Slide 1 Exporting Data and Creating Financial Reports with Excel and Crystal By Peter.
Graphing with Excel: Graphing Made Easy Mac 2008 Version.
How to Make School Comparison Graphs in Excel Please follow the instructions as closely as possible. When you get used to using Excel for this then feel.
Codesoft Label Creation. Codesoft Edition Overview Editions of Codesoft include: Codesoft Print Only – open and print files created in other versions.
Making Tables and Graphs with Excel The Basics. Where do my IV and DV go? Just like you would create a data table on paper, your IV goes in the leftmost.
Creating Graphs in Excel. Step Summary Input data Highlight data to be graphed Insert  Chart Decide what type of graph to use Finish!
Graphing in Science. Types of Charts  Most scientific graphs are made as line graphs.  However, occasionally bar graphs, pie charts, or scatter plots.
11 Chapter 3: Getting Started with Tasks 3.1 Introduction to Tasks and Wizards 3.2 Creating a Frequency Report 3.3 Generating HTML, PDF, and RTF Output.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
Graphing. The Important Elements of a Graph  Horizontal Axis (X-Axis)  The Independent Variable. A change in this variable affects the y variable. 
Making a Pie Chart In Microsoft Excel For PowerPoint WHAT MY DAY IS LIKE.
MySQL + PHP.  Introduction Before you actually start building your database scripts, you must have a database to place information into and read it from.
Computers: Tools for an Information Age Chapter 12 Spreadsheets and Business Graphics: Facts and Figures.
Ranjeet Department of Physics & Astrophysics University of Delhi Working with Origin.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Access 2002 Advanced Report Design.
How To Make a Graph (The Right Way)
Pi In The Sky (Web Interface) Gaston Seneza Philander Smith College, Little Rock, AR SIParCS Intern Mentors: Dr. Richard Loft & Dr. Raghu Raj Kumar 1.
Why Icon? An icon is a small picture that represents a file. Icons help you execute commands, open programs or documents quickly. It is also useful to.
Chapter 5: Charts Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
With Microsoft Office 2007 Intermediate© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Office 2007 Intermediate.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
ITS-VIP SPRING 2012 FINAL PRESENTATION DATA MINING GROUP PHP?HTML INTERFACE Mide Ajayi Nakul Dureja Data Miners Rakesh Kumar David Fleischhauer.
Open Your Mind to Open Source MPDO’s & EOPR’s Centre for IT & eGovernance AMR-APARD Hyderabad Welcome!
16 Graph Skills How to read and understand advanced types of bar charts, area graphs, climographs and triangle graphs How to advance their skills of drawing.
Introduction to Enterprise Guide Jennifer Schmidt Rhonda Ellis Cassandra Hall.
HS115 Unit 7 Seminar December 22, 2010 David Rudnick, Instructor.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)Graphics.
Copyright 2007 Paradigm Publishing Inc. EXCEL 2007 Chapter 7 BACKNEXTEND 7-1 LINKS TO OBJECTIVES Create a Chart with Data in a Worksheet Create a Chart.
Copyright © 2008 Pearson Prentice Hall. All rights reserved Committed to Shaping the Next Generation of IT Experts. Chapter 5 Charts and Graphs Robert.
Bar Graphs Used for comparing separate groups. Axes X- axis: independent variable (what the scientist controls) Horizontal D – dependent R – responding.
Google Charts API Ashwin Neurgaonkar 10/13/2008. What are APIs ? API stands for ‘Application Programmable Interface’. As it’s name implies, it is an interface.
EXCEL CHARTS. CHARTS Charts provide a way of presenting and comparing data in graphical format. Embedded charts or chart sheets Embedded charts are objects.
Exploring Microsoft Excel 97 Chapter 4 Graphs and Charts: Delivering a Message Office graphic copyright by Microsoft Corp.
DAY 6: MICROSOFT EXCEL – CHAPTER 3 Sravanthi Lakkimsetty September 2, 2015.
WORD VOCABULARY LIST #5 MICROSOFT OFFICE WORD VOCABULARY LIST #5 bar chart - A chart with bars that compares the quantities of two or more items.
Creating Graphs in PowerPoint Step 1 Open a new PowerPoint Document.
Graphs and How to Use Them. Graphs Visually display your results and data Allow you (and your peers) to see trends Help to make conclusions easier Are.
Chapter 2:Excel. Determining Results with the if Function =IF(logical_test, value_if_true,value_if_false) The IF function has three arguments: – A condition.
PHP getting data from a MySQL database. Replacing XML as data source with MySQL Previously we obtained the data about the training session from an XML.
Graphs and Graphing Data Biology Ms. Haut. Introduction to Graphing Both figures display the same information, but differently. Which figure is easier.
CRSD Technology Training Tony Judice. Quick Access Toolbar – can be modifiedSave as… allows you to save the file to a different location and also as an.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
1. Tables, Charts, and Graphs Microsoft Word & Excel 2003.
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
Chapter 15: Spreadsheet and Worksheet Basics Lesson 96: Worksheets with Charts © 2010, 2006 South-Western, Cengage Learning.
Matlab tutorial course Exercises 5: Loading and writing images
Bar Graphs, Pie Charts, and more.  The first thing we will discuss is the area principle, which basically states that each unit in our sample should.
LESSON 6 Working with Charts. Each chart type has its own collection of sub-types that provide various alternate formats for the selected chart type.
Graphing. Line Graphs  Shows a relationship where the dependent variable changes due to a change in the independent variable  Can have more than one.
Charts MOAC Lesson 6.
Submitted by: DRPU Software Team Site:
[Charts| Generating Graphic| Creating Graphic]
Charts MOAC Lesson 6.
How to make great graphs that make sense!
Cartography and Labeling
Using Excel to Make a Graph
CSc4730/6730 Scientific Visualization
Charts MOAC Lesson 6.
Presentation transcript:

Using PHP, MySQL and JpGraph to Create Dynamic Graphs By: Geoffrey Rowland (geoffrey.rowland@noaa.gov)

Why Dynamic? Less time spent to implement dynamic graphs than to manually create a new graph everytime you need one Never use PowerPoint / Excel to create graphs again! (okay maybe not) Useful for data that changes often

Required Software PHP 4.02 and above Compiled with GD Library Jpgraph 1.63 graph class library MySQL (or database to your liking)

GD Graphics Library GD allows the ability to use code to quickly draw images complete with lines, arcs, text, multiple colors, and write out the result as a PNG, JPEG, or WBMP file. Does not support GIF due to patent issues.

Jpgraph Graph Class Library Object oriented graph library for PHP Allows creation of bar, line, and plot graphs Also allows creation of pie charts Database independent QPL 1.0 license

Example Input for Graph Creation

Include Graphing Libraries and Setup Database Connection <html> <body> <? //make sure default image format is jpeg, not png DEFINE("DEFAULT_GFORMAT","jpeg"); // include jpgraph graphing libs.. include ("jpgraph/jpgraph.php"); include ("jpgraph/jpgraph_line.php"); include ("jpgraph/jpgraph_bar.php"); //include db connection details include("/home/em-dat/dbconnect/dbconnect.php"); // connect PHP to MySQL $linkID=MYSQL_CONNECT($hostname,$username,$password) or die("Unable to connect to database"); mysql_select_db("$dbName", $linkID) or die("Unable to select database"); // query to select our information for the x and y axis for the bar graph $query4 = "select year,sum($number) AS summedTotal FROM emdat WHERE DisType = '$DisType' AND country = '$country' AND year between '1975' and '2001' group by year order by year"; // execute the query $result4 = mysql_query($query4,$linkID);

Load Data from Database into X and Y axis Array $readnext = TRUE; // use $year value if there is no value for that year in the database for ($year=1975; $year < 2002; $year++) { if ($readnext) $row = mysql_fetch_row($result4); if ($year==$row[0]) // if there is data for that year, load the year and assoc. data into the array. // xaxis array $databarx[]=$row[0]; // yaxis array $databary[] = $row[1]; $readnext=TRUE; } else { // if there isn't data for that year, load the year into the array, but load a 0 value for that year. $databarx[] = $year; $databary[] = "0"; $readnext=FALSE;

Set Graph Properties $graph->img->Image(640,480,"jpeg"); $graph->SetColor("$color_background"); $graph->SetShadow(); // Use text X-scale so we can text labels on the X-axis $graph->SetScale("textlin"); // Color the two Y-axis to make them easier to associate // to the corresponding plot (we keep the axis black though) $graph->yaxis->SetColor("black","black"); // Set title and subtitle $graph->title->Set("Number $number during $DisType in $country between 1975 and 2000"); // Make the margin around the plot a little bit bigger than default $graph->img->SetMargin(70,140,70,80);

Create the Bar Graph // Setup the labels $graph->xaxis->SetTickLabels($databarx); $graph->xaxis->SetTextLabelInterval(5); $graph->xaxis->SetTextTickInterval(1); // Create the bar graph $bar1 = new BarPlot($databary); // set the title of the legend and the color of the bars $bar1->SetLegend("Number $number"); $bar1->SetFillColor("$color_bar"); // set width of bars on bar graph $bar1->SetAbsWidth($barwidth); //show value on top of bar $bar1->value->Show(true); // set format of values displayed, %d prints no decimal places $bar1->value->SetFormat("%d");

Output Bar Graph to Screen $graph->Add($bar1); // Finally output the image // write the image to disk, and call it dynamic-bar.jpg $graph->Stroke("dynamic-bar.jpg"); // Calculates the MD5 hash of server timestamp and returns that hash to $cachekiller. // The hash is a 32-character hexadecimal number. $cachekiller = md5(time()); // output the print icon echo "<a href=\"javascript:window.print()\"><font color=\"#FFFFFF\">..<img src=\"http://www.em-dat.net/pagepics/printicon.gif\" width=\"16\" height=\"14\" border=\"0\" alt=\"Print this page.\"></font></a><br>"; // output the graph to the screen with cachekiller number that makes the browser refresh the image echo "<img src=\"dynamic-bar.jpg?cachekiller=$cachekiller\">"; ?>

Example Output Bar Graph

Example Graphs

Additional Information Climate Information Project http://www.cip.ogp.noaa.gov JpGraph http://www.aditus.nu/jpgraph/ PHP http://www.php.net MySQL http://www.mysql.com GD Graphics Library http://www.boutell.com/gd/

Contact Information Feel free to contact me with any questions! geoffrey.rowland@noaa.gov