Using the RPG Graphical Chart Engine to Create Graphs
Certain personalities, sometimes my own included, need to visually see pictures of numbers to make sense of data vs. taking a gander at green-bar paper with the same information. What's even funnier is how a Web site that contains tons of solid functionality can be considered a complete failure if eye candy isn't present. So, in the interests of keeping our dying breed alive (that dying breed being RPG-burger-flippin' programmers), I have developed an engine of sorts that will allow RPG programmers to generate eye-catching jaw-dropping graphs that can show customers and higher ups that RPG and the System i platform (coupled with some open-source Java) still has what it takes to thrive in the next generation of computing and presentation.
Anyway, enough preaching to the choir. The tool, the "RPG Chart Engine," produces charts like the one shown in Figure 1.
By simply making some straight-forward calls to the RPG Chart Engine service program you can accomplish charts like Figure 1 and more (see notes at bottom for links to more examples). Below is the RPG code to produce the pie chart in Figure 1. Of course the values in this example program are hard-coded for brevity sake and normally data would be pulled from your DB2 files.
H dftactgrp(*no) bnddir('RCEBND')
D uid s 15p 0
*on: *on: *on: '/home/aaron/pie123.jpg': 700: 300);
RCE_addPieChartData(uid: 'January': 3100.50);
RCE_addPieChartData(uid: 'February': 5100.50);
RCE_addPieChartData(uid: 'March': 7100.50);
RCE_addPieChartData(uid: 'April': 1100.50);
*inlr = *on;
Let me explain the above code a little. Starting at the top, you can see a binding directory of RCEBND used to aid in finding the RCESV service program at compile time. Next RCECp is copied into the program via "/copy," which contains the necessary prototypes and variables to accomplish the various calls to the RPG Chart Engine. It should be noted that two DB2 tables--RCEHDRPF and RCEDTAPF--receive data from the RPG Chart Engine sub procedures behind the scenes. Each of these tables has its records made unique by specifying an integer column with a number that's pulled from a data queue. Because that's in the guts of service program RCESV you really only need to know a unique integer is returned when RCE_newPieChart is called and the returned value is stored in variable uid. The variable uid then must be specified on all subsequent calls to RCE_addPieChartData so the pie chart data can be matched up with the record in RCEHDRPF. Next make multiple calls to RCE_addPieChartData specifying the uid of this report along with the actual data this report should be based on (e.g., January, 3100.50).
comments powered by