This chapter describes how to create databound graphs in ADF Swing panels. The graph component allows you to display data through a wide variety of graphs.
This chapter contains the following sections:
JDeveloper lets you create a graph component that binds with data sources from any of the business services supported in Oracle ADF. Supported business services include ADF Business Components, Enterprise JavaBeans (EJB), Toplink, Web Services, and custom JavaBeans.
Note:
In order to work with graphs, your business service must be able to provide data in the format expected by the graph component, as described in Section 6.2, "How to Create a Graph for an ADF Swing Panel."
You can use the JDeveloper Data Controls panel to drag data model components such as ADF Business Components view objects onto panels. At any time after creating an ADF databound graph component, you can change the graph properties using the design-time facilities of JDeveloper.
JDeveloper also provides support for building databound graphs through its seamless integration of Oracle Business Intelligence Beans (BI Beans) technology. Although you do not need to install the BI BeansJDeveloper addin component to use the graph technology, you may want to install the addin to view the available documentation.
The graph component capabilities and features include:
Easy to integrate with custom applications
Since a graph component is reusable, you can add it to custom applications, including ADF web applications (currently JSP pages only) and ADF Swing applications.
Easy to build and maintain
You can use the Data Controls panel to drag data model components such as ADF Business Components view objects onto the form. The graph properties and databinding are exposed in the Properties window to enable the developer to quickly change these settings.
Programmatic access through Java
You can modify graph components by calling the BI Beans Graph component's public methods.
Support for different data sources
ADF Business Components, Enterprise JavaBeans, Toplink, Web Services, custom Java Beans
Generate simple and master-detail graphs
Small downloads
Excellent performance when deployed
The ADF Swing oracle.jbo.uicli.jui
package includes the following classes which are related to the databound graph component:
JUGraphBinding
JUSingleTableGraphBinding
JUMasterDetailGraphBinding
Table 6-1 suggests graph types for different aspects of data that you want to emphasize in a graph.
Data Aspect | Example | Graph Type |
---|---|---|
The difference between items over time or at the same point in time |
Which products are selling best in which stores? |
Clustered bar or 3-D bar |
Trends over time |
Is our market share increasing or decreasing? |
Absolute line or Stacked area |
Cyclical trends over time |
Have the sales of this product peaked in March consistently over the past three years? |
Radar graph |
Rate of data change |
How fast is our market share increasing? |
Absolute line or Stacked area |
Percentage or changes in percentage |
How much of our revenue comes from each product line? Is our big seller bringing in the same percentage of revenue as it did last year at this time? |
Pie or Percentage bar, line, or are |
Relationship of parts to the whole |
Which products' sales are most closely related to our total sales? Which products' sales follow the trend of the total sales? Which ones do not? |
Pie, Percentage bar or line, or Stacked bar, line, or area graph. |
Relationship of parts to the whole, with more detail for one of the parts |
Which product line accounts for the highest percentage of sales? Within that product line, which districts make up the most sales? |
Pie-bar |
Changes in all parts of a whole |
Do the products that bring the most revenue to the entire company bring in the most revenue for each district? |
Multiple pie or Stacked bar, line, or area |
Relationships between two variables |
Do sales increase when we spend more on marketing? |
Scatter or Polar |
Relationships between three variables |
Do sales and profits increase proportionally when we spend more on marketing? |
Bubble |
Location of defects in a system |
Where are the highest percentage of defects occurring? |
Pareto |
You can set an ADF graph binding for a graph component that you insert from the Data Controls panel into an ADF Swing panel.
To understand the selections you make when building the graph component, you must understand how the graph component obtains sufficient data from your ADF Business Components data sources to:
Plot each graph marker (as determined by up to three data points)
Label each graph group, for example, the months of the year
Draw either a single series or a multi-series type graph
Label each graph
The data binding is determined in the Graph Editor by the data model components that you select (for example, the attributes of an ADF Business Components view object). The Graph Editor helps you choose objects and attributes for a particular graph type, but you must be familiar with the data model in order to make the specific choices. In general, when you make a graph type selection, the Graph Editor displays one attribute for each data point value needed to draw the markers for your graph type. If you select a group type graph, the Graph Editor also prompts you to choose an accessor that links the master data collection with the correct detail data collection.
For instance, if you want to plot a Hi-Lo-Close (HLC) Stock graph type for multiple stocks in the Graph Editor, you must choose:
The master data collection that contains one row for stock type
The detail data collection that contains the rows corresponding to the data of each stock
The attribute from the master data collection that specifies the label for each stock graph
One attribute from the detail data collection for each marker data value (in this case, Hi, Low, and Close)
Whereas, if you decide to plot a single stock as a simple bar graph that shows monthly high values in the Graph Editor, you must choose:
An unconstrained data collection (one that does not belong to a master-detail relationship)
One attribute that provides the label for each month
One attribute for the marker data value (in this case, Hi value only)
It is helpful to understand how the graph component interprets the data from the business services data model. In general, the requirements of the data model for your data model project depend on:
Whether the graph type you select requires one, two, or three data point values to determine each graph marker
Whether you want to plot a series (single table) or a group type (master-detail) graph
For example, assume you want a simple graph, such as a bar graph with the data shown in Example 6-1.
Each row in the table corresponds to a series in the graph and each column corresponds to a group.
Some types of graphs, like the bar graph, require one value per marker. This is in contrast to other graph types, like the stock HLC graph, which require three values per marker (high, low and close). When your graph requires multiple data values, it is convenient to store them in separate rows in your database table, as shown in Example 6-2.
Example 6-2 Storing Multiple Data Values
Date High Low Close 10 Jun 03 11 10 11 11 Jun 03 11 7 9 12 Jun 03 10 9 9.5
The graph component supports the type of graph whose data is stored in a single table. When your graph requires multiple values, then the data for the chart should be modeled as a master/detail relationship. Each detail provides one series of data, corresponding to the master value. In the stock graph example above, the data model could look like Example 6-3.
Master table stock_ticker_table -------------------------------- ticker symbol Oracle Corporation ORCL XYZ Corporation XYZ Detail table stock_price_table ----------------------------------- ticker Date High Low Close ORCL 10 Jun 03 23 22 23 ORCL 11 Jun 03 24 23 23 ORCL 12 Jun 03 25 24 24 XYZ? 10 Jun 03 10 9 9 XYZ 11 Jun 03 10 9 9 XYZ 12 Jun 03 10 8 9
In a single-table graph, the data model is simple and need only contain:
A standalone data collection, where each row plots one graph marker
One attribute that supplies the label for the groups that the graph displays
One attribute per graph data point, with as many attributes as required to plot each graph marker
In a more complex group type graph, the data model is based on a master-detail relationship and must contain:
A master data collection, where each row specifies one series but contains no data
One master data collection attribute that supplies the label for each series
One detail data collection for each series, where each row plots one graph marker for that particular series
One detail data collection attribute that supplies the label for the groups displayed by the graph
One detail data collection attribute per graph data point, with as many attributes as required to draw each graph marker
In the user interface project, open the Java visual editor on the data panel or form.
For more information, see Section 3.3, "How to Insert UI Components into ADF Swing Panels."
In the Data Controls panel, drag the collection you want to bind to the graph component into the open form or panel.
From the Add Child popup list, select Graph.
In the Java visual editor, click the Bindings tab, select the graph component binding from the list and click Edit.
In the Graph Editor, choose what specific data will appear in the graph such as the view selection, series attributes, and data attributes.
When you create a graph component, JDeveloper generates files which describe the graph properties and associated data binding information. JDeveloper generates and updates the files shown in Table 6-2.
Table 6-2 Files Generated for Databound Graph Components
File | Description |
---|---|
|
The Java implementation of the graph component which lets you programmatically set and get graph properties. |
|
The graph properties definition file. |
|
The ADF bindings definition file containing the ADF data binding information for the graph. |
The files are added to the project and are accessible from the Applications window. They reside in /src/client
directory relative to the application.
Example 6-4 shows a sample PageDef.xml
file for a graph component in an application consisting of an ADF Swing panel and ADF Business Components for the business service.
Example 6-4 Sample PageDef.xml File for a Graph Component
<?xml version='1.0' encoding='ISO-8859-1' ?> <DCContainer id="untitled1PageDef" xmlns="http://xmlns.oracle.com/adfm" Package="view" > <Contents > <DCIterator id="model_AppModuleDataControl_EmployeesView1Iter" Binds="model_AppModuleDataControl.EmployeesView1" > </DCIterator> <DCControl id="EmployeesView1" DefClass="oracle.jbo.uicli.graph.JUSingleTableGraphDef" SubType="DCGraph" ControlClass="oracle.dss.graph.Graph" IterBinding="model_AppModuleDataControl_EmployeesView1Iter" SeriesType="SINGLE_SERIES" SeriesLabel="EmployeeId" GraphPropertiesFileName="view.BIGraphDef1" > <Contents > <AttrNames> <Item Value="EmployeeId" /> <Item Value="Salary" /> <Item Value="CommissionPct" /> <Item Value="ManagerId" /> <Item Value="DepartmentId" /> </AttrNames> <ColumnLabels> <Item Value="EmployeeId" /> <Item Value="Salary" /> <Item Value="CommissionPct" /> <Item Value="ManagerId" /> <Item Value="DepartmentId" /> </ColumnLabels> </Contents> </DCControl> </Contents> </DCContainer>
Example 6-5 shows a sample DataBindings.xml
file for a graph component in an application consisting of an ADF Swing panel and ADF Business Components for the business service.
Example 6-5 Sample DataBindings.xml file for a Graph Component
<?xml version='1.0' encoding='ISO-8859-1' ?> <JboProject id="DataBindings" xmlns="http://xmlns.oracle.com/adfm" SeparateXMLFiles="false" Package="" ClientType="Generic" > <Contents > <DataControl id="model_AppModuleDataControl" SupportsFindMode="true" SupportsTransactions="true" Package="model" Configuration="AppModuleLocal" FactoryClass="oracle.adf.model.bc4j.DataControlFactoryImpl" > </DataControl> <Containee id="untitled1PageDef" ObjectType="BindingContainerReference" FullName="view.untitled1PageDef" > </Containee> </Contents> </JboProject>
At any time after creating a databound graph component, you can change graph properties using the design-time facilities of the Graph Editor. The Graph Editor displays a visual representation of the databound graph using psuedo-data not actual data. For example, you may want the graph to display using a different graph type or graph style.
To edit an existing graph component:
In the Applications window, expand the user interface project and right-click BIGraphDefx.xml in the view package and choose Open.
In the Graph Editor, from the editor's toolbar, select either Graph Type or Format Graph.
When you select Graph Type, you can select another graph type to display the data or change the graph's appearance or style.
Click the appropriate tab to display its related settings.
When you select Format Graph, you can change the graph's titles, legend, plot area, and X- and Y-Axis settings.
Click the appropriate tab to display its related settings.
You can also edit the graph's properties by selecting an element in the Structure window and double-clicking to display its property settings in the Properties window.
Note:
If an error message displays about insufficient data, select another graph type as the data model you specified does not contain enough data columns to render the graph. For example, line graphs require more than one data column. For a description of the available graph types, see Section 6.1, "Graph Types."
At any time after creating a graph for ADF Swing panels, you may decide to display other data in the graph. The Customize Graph Binding editor lets you select another data source for the graph. However, if the data source belongs in another data model you will need to create a new databound graph, as described in Section 6.2, "How to Create a Graph for an ADF Swing Panel."
In the Applications window, with the form containing the graph component open in the Java visual editor, select the Bindings tab.
In the Bindings and Executables page, select the graph binding and click Edit.
In Graph Editor, select another iterator from the dropdown list.