Perforce JViews Charts Sample: Adding Highlight Interaction


Description

This sample shows a data set rendered as two different graphical representations (as a pie chart and a bar chart). These charts react to mouse movements by highlighting the data point over which the mouse cursor is placed.

How to Use the Sample

The main frame contains a pie chart and a bar chart displaying the same data set. Two kinds of interactions are provided:

How to Run the Sample as an Application

This sample can be run as an application. The installation directory contains an executable JAR file, highlight.jar, that allows you to execute the sample with a double click from a file browser. Note that if you are using Internet Explorer, you can open the installation directory and execute the JAR file from the browser. This technique may not work in other Web browsers.

Alternatively, you can run the sample application from the command line. First check that the Ant utility is properly configured. If not, see the instructions on how to configure Ant for Perforce JViews.

Then, go to the installation directory of the sample and type:

ant run

Topics Covered

Detailed Description

In this sample, we use the IlvChartHighlightInteractor class to be notified whenever the mouse passes over the graphical representation of a data point. This notification is received by a custom ChartInteractionListener, which implements the following behavior:

The rendering style associated with a given data point is computed through an implementation of the IlvDataRenderingHint interface. Each time a data point is about to be drawn by its renderer, its specific rendering hint is used instead of the renderer one, allowing you to locally customize the way a data point is drawn. Note that another way to use an IlvDataRenderingHint is to associate it with all the data points of a data set. In this case, the rendering hint is said to be global to the data set.

The label annotation is rendered through an instance of IlvDataLabelAnnotation. This class should be used for data point labeling, to display the data value (or a specific label) of a data point. Similar to the rendering hint, a data annotation can be set either globally for a data set, or individually for a given data point.

Note that no explicit repaint request is necessary as the chart is updated automatically when the above operations are performed.

Installation Directory

The Adding Highlight Interaction sample is installed here.

Classes Involved

Source Files

Copyright © 2021 Rogue Wave Software, Inc., a Perforce company. All rights reserved. Legal terms.