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
- Moving the mouse over both charts highlights the data pointed to by the cursor.
- Clicking a slice of the pie chart toggles its exploded state.
- Clicking the toggle button switches between a 3-D and a 2-D display.
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
- Using chart interactors to perform data picking and highlighting.
- Setting rendering hints and annotations on data points.
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:
- When a new point is highlighted, a brighter rendering style is set for the highlighted point, as well as a labeled annotation displaying its value.
- When a point is unhighlighted, the rendering style and annotation previously set are removed so that the point is rendered using the default renderer style.
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
- ilog.views.chart.interactor.IlvChartHighlightInteractor
- ilog.views.chart.graphic.IlvDataAnnotation
- ilog.views.chart.graphic.IlvDataLabelAnnotation
- ilog.views.chart.graphic.IlvDataRenderingHint
- ilog.views.chart.renderer.IlvPieChartRenderer
- ilog.views.chart.IlvChart3DView
Source Files
- highlight.HighlightDemo
- highlight.HighlightHint
- highlight.HighlightListener
- highlight.ExplodeSliceListener