Home > AS/400 Tips > WebSphere Strategies for iSeries professionals > How to produce iSeries graphs on Web pages
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

WEBSPHERE STRATEGIES FOR ISERIES PROFESSIONALS

How to produce iSeries graphs on Web pages


Paul Holm
11.17.2005
Rating: -4.25- (out of 5)


iSeries news and advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


Paul Holm
Paul Holm
The iSeries has been beaten up for years for its ugly green screens, but Web technologies can change all that. This tip will show how Web applications can easily create dynamic graphs using standard technologies such as SQL and HTML. There are many advanced and more sophisticated graphing techniques and package such as JFreeChart or integration with MS Excel, but if the following techniques can achieve your goal it can be done quickly and without cost.

Note: It is assumed the reader has an understanding of SQL/JDBC and HTML. If not, check out http://www.w3schools.com

The problem

Management wants to see data and an associated graph of unit sales by region.Getting the data is easily accomplished using standard SQL, but how do you get a graph on a Web site? The following is what we want to produce:

sample Java web graphic on iSeries

Step 1: Using a JPG image

Many graphing requirements can be achieved by showing images (JPG or GIF files) along with the data. An image can be created with any standard graphics software such as Paint Shop. Below is a JPG image that is a single pixel wide. (Look closely because it is just a sliver.)

sample Java web graphic on iSeries

Once you have an image, you can adjust the image width to produce the dynamic sizing. For example, this HTML produces the below graphic bar:

<img src="http://www.planetjavainc.com/wow63x/images/wowGraphRed.jpg" border=0 height = 25 width="416"/>

And this HTML produces the smaller graphic bar below:

<img src="http://www.planetjavainc.com/wow63x/images/wowGraphRed.jpg" border=0 height = 25 width="16"/>

sample Java web graphic on iSeries

In these examples, a single pixel graphic named "wowGraphRed.jpg" is referenced in an HTML image tag, but the width is set to 16 pixels wide for the small graphic and 416 for the long chart element (see the width parameter). Given this, charts can be produced from normal graphics by simply varying the width tag. Simple enough, eh?

Step 2: Dynamically varying the image width

The next job is to produce the HTML image tags with dynamic data. The standard way to access data is via SQL. We can use SQL to dynamically produce a String field that represents the HTML tags. Examine the following SQL:

SELECT region, sum(sales) as sales , '<img src="images/wowGraphRed.jpg" border=0 height = 25 width="' || char(sum(sales)) || '"/>' as graphDD FROM pjdata.sales group by region order by region

In the above SQL, we select the region and sum of the sales amounts and then use concatenation to produce a String that represents the HTML tag. Note: The || perform the concatenation of the String elements and the "char(sum(sales))" is SQL that produces an integer that is the sum of sales. This is the dynamic width value. The group by clause causes sales to be summed by the region.

Step 3: Putting it together

The SQL/JDBC above is executed by your Web application, and the results are extracted using standard JDBC Java programming. The field called "graphDD" is a string field and has the HTML image script needed to produce the chart. A servlet or JSP can simply produce the end result by creating an HTML table that includes the image tags produced dynamically by the SQL. As the data changes, the image length changes dynamically.

Run the following link and view the source from your browser to further analyze the results.
http://www.planetjavainc.com/wow63x/runApp?id=390&_pj_lib=wowsamp60

Summary

This tip showed you how to use a standard image, HTML and SQL to produce a simple but useful application with dynamic graphing from your iSeries data. If you're not familiar with JDBC, send an e-mail me at pholm@planetjavainc.com and I'll send you the code that performs that segment.

Happy graphing!

---------------------------
About the author: Paul Holm is an iSeries WebSphere and Java specialist at PlanetJ Corp. He worked for IBM-Rochester for over 10 years as a DB2/400 and Java/WebSphere developer.


Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
WebSphere Strategies for iSeries professionals
Application modernization strategies for System i
Application modernization in the i world
Natively supported Web applications for Power running i
Enterprise open source basics
Basic security considerations for a Domino/WebSphere system
Simplifying data access using Java Standard Tag Library
Integrating Microsoft ActiveX components with WebSphere
Choices for running Web workloads on iSeries
Virtual hosting for iSeries Web applications
Automate WebSphere configuration backups on the iSeries (i5)

iSeries Java programming
Groovy programming on IBM i
EGL Rich UI on IBM i: Do you Dojo?
Programming for the Web on the IBM i, what is possible
Database performance comparisons on IBM i
Database drivers on the i: MySQL vs. IBM Toolbox
How to: Output SQL script to a text file from an AS/400
Application modernization for the iSeries: Why bother?
JDBCODBC functionality -- Java to Excel for complex workbooks
Necessity leads to iSeries Watchdog development
Accessing AS/400 data using Excel ODBC drivers
iSeries Java programming Research

Web Development
Implementing a browser interface in COBOL: Creating your graphic Web page
Implementing a browser interface in COBOL: Getting started
IBM i shop boosts online sales with RPG-based Web platform
Migrating from RPG to EGL on IBM i
Groovy programming on IBM i
Running PHP open source applications: NOBODY needs authority
Zend Web software teams up with IBM System i
The best technologies and tools for System i programmers in 2009
Seven IBM i project lessons learned in 2008
AS/400 lessons from the past, present, and future: A holiday tale

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
WebSphere Development Studio Client (WDSC)  (Search400.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts