Chart java beans - Release 1.1

Contents

Changes
Gallery
Application examples
Using the beans
More about the utility beans
Reference
Known restrictions

Changes

This package contains the following changes and new features:

  1. Chart beans are now lightweight JFC components.
  2. A separate bean is provided for each chart type. The UniversalChart bean can be used by applications that need to switch chart type dynamically through an API.
  3. The new ChartDataReducer bean can be used to coerce large data sets into a form suitable for presentation by the chart beans.
  4. Charts now support x axis labels.
  5. Charts now provide tooltips to show the value of each chart item.

Gallery

This package contains a set of lightweight beans for drawing simple business charts. The design-point is "small and simple" to support the practical use use of charting within intranet/internet applications.

The Chart bean takes a 2d array of numerical values to create any of the chart types shown below. You can customize the bean to define the chart type, legends, item colors, y axis labels and scaling. You can also edit standard Java component properties such as size and shape, foreground and background colors, and font.

Gallery of chart types

Application examples

Product sales

Sales chart

The product sales application displays a chart of sales data extracted from a separate SalesData class. The user can select the chart type, product group, and presentation style.



Pressure chart

Pressure chart The pressure chart application monitors an industrial device in real time to show the current pressure and the device safety limit. It also tracks the minimum and maximum pressure recorded since starting monitoring. The chart is rolled to show the last 10 value groups and switches the pressure line to red whenever the safety limit is exceeded.


Using the beans

You can either use the beans in a visual composition tool, such as Visual Age for Java, or as Java components manipulated through an API. Although most properties can be edited through visual composition tools, there are some restrictions documented below.

Using the beans in a visual composition tool

This section describes some common scenarios for building applets by using a visual tool such as Visual Age for Java or Lotus bean machine.

You will need to adapt the scenarios to the specific terminology and connection techniques of the tool you use.

Most tools require you to import the jar before you can use the beans. The tool may also allow you to add the chart beans to a palette.

Creating a static chart

Use this scenario when the chart values and attributes are defined at design time.

  1. Instantiate a Chart bean
  2. Position and size the bean
  3. Use the property editors to edit:
    • data values
    • legends
    • y axis properties
    • component properties such as foreground and background colors and font.

Creating a dynamic chart using 2d data from another bean

Use this scenario to derive chart data from another bean capable of supplying a 2d array of numeric values.

  1. Instantiate a chart bean
  2. Instantiate the data source bean
  3. Connect the data source bean
    • In response to the appropriate event:
      • call set Data Values on the chart
      • pass a 2D numeric array as the argument.

Creating a dynamic chart using scalar data from other beans

Use this scenario to derive chart data from one or more beans capable of supplying data as a scalar value

  1. Instantiate a Chart bean.
  2. Instantiate a ChartDataAggregatorBean.
  3. Instantiate data source beans as required.
  4. Connect the ChartDataAggregator bean to the Chart bean:
    • in response to a property change event:
      • call set data values on the chart
      • use property data values as the argument.
  5. Connect the data source bean or beans to the ChartDataAggregator bean:
    • In response to the appropriate event:
      • pass a value to the aggregator by calling either its set... or its add... methods.
      • Call set... methods to set a value at a specific group and value index.
      • Call add... methods to add a new value at the next unused value or group of values.

Visual Age example

This example illustrates the use of the chart and utility beans in Visual Age for Java.

In this application, a user types a set of values into entry field 1. The values are aggregated into an array by a chart data aggregator 2 and the array is reduced to 5 smoothed values by a chart data reducer 3 and then passed to a chart 4 for display.

Visual Age screenshot showing linked beans

To connect the entry field 1 to the aggregator 2:

To connect the aggregator 2 to the reducer 3

To connect the reducer 3 to the chart 4

To customize the reducer:

Using the beans in a Java program

Sales chart example

This example demonstrates how to use the Chart bean to graph sales results. It illustrates the following techniques:

Sales chart

View the source code

Pressure chart example

This example demonstrates how to use the Chart bean to display a rolling plot of device pressure. It illustrates the following techniques:

Sales chart

View the source code

Reduced Sales chart example

This example demonstrates how to use the ChartDataReducer bean to control the amount of data the Chart bean displays. It illustrates the following techniques:

Reduced sales chart

View the source code

More about the utility beans

More about the Chart Data Aggregator bean

Each value in the aggregator is identified by a group index and a a value index within the group. The following diagram shows how group and value indices identify segments in a stacked bar chart.


    | Group1
    | Value2
    |
    | Group1  Group2
    | Value2  Value2
    |
    | Group1  Group2
    | Value1  Value2
    +---------------

To set specific values, use the following sequence of method calls:

Alternatively, you can add values or groups of values at the next spare index:

When you use add... methods, you can roll the chart after a specified number of groups by setting on the rollActive property and specifying a group count in the rollAfter property. This property has no effect on set... methods.

Whenever a value is set or added, the bean fires a property change event. You can use this event to trigger sending the updated values to the Chart bean.

You should not mix calls to set... methods and add.... methods.

More about the Chart Data Reducer bean

The reducer bean is used as a piping bean between the chart bean and the data source in order to control the amount of data the chart is to display. It may be desirable occasionally to focus on a particular section of the data in the chart or to give a general trend of the data which is possible by using the reducer bean.

The data source is simply plugged into the Input Data property of the reducer and the output data is fed into the chart. The way the data is reduced is controlled with the Reducing Rule property which allows the extraction of:

Where n is set by the Number of Output Columns property

The data is reduced, using the property values set, whenever a call to getOutputValues is made which returns the reduced output.

Reference

Bean properties

JavaDoc API reference

Known restrictions

(c) Copyright IBM Corp. 1998,1999