This demo shows how labels can be added to common charts to bring them alive.The top chart illustrates how labels can be added at pixel locations, specific values in axis coordinates, or attached to data items. One label of each type has already been added to the chart. To add more, select one of the labels in the control panel at the right of the chart and then click on the chart. When doing this,
coordToDataIndex()
andcoordToDataCoord()
are used to determine the position and text of the labels.The control panel to the right of the top chart also allows the properties of each chart label to be changed. The Anchor property determines how the label is positioned with respect to the point it is connected to. The X Offset and Y Offset properties determine the distance between this point and the label. The Connected property determines whether a line is drawn between a point and it's respective label. Although the fields in the control panel affect all chart labels on the chart in this demo, it is possible to set these values differently for each individual label.
The bottom chart illustrates that chart labels can be made to pop up as you drag your mouse over the graph. These are called dwell labels. Toggle the Dwell Labels checkbox in the control panel at the right to switch between static and dwell labels. Change the value of the Chart Type combo box to see how the labels look by default when used with different chart types.
The label at the top of the bottom chart illustrates that any class derived from JComponent can be placed inside a chart label. In this case, the label contains a JButton. When pressed it will bring up another chart label that contains either an HTMLPane (K Version) or a JPanel containing several labels (J Version).
Copyright© 2004 Quest Software Inc..