The Graph bean also provides a Java API for imagemap information. You can retrieve an
enumeration of ImagemapComponent
objects. Each ImagemapComponent
describes one graph component, providing a ComponentHandle
object and a polygon
for the component. To get the enumeration of objects, you call the
getImagemapEnumeration
method of the graph.
The following example saves information about a graph to an enumeration. The enumeration
will have an ImagemapComponent
for each data marker and for each component in the
legend, including the legend area.
writer.println( "<IMG SRC=/"testmap.gif/" USEMAP=/"#ELEMENTS/" BORDER=NONE>" ); writer.println( "<MAP NAME=/"ELEMENTS/" >" ); //get ImagemapComponents for data components and for the legend Enumeration map = graph.getImagemapEnumeration( Graph.MAP_DATA | Graph.MAP_LEGEND ); while( map.hasMoreElements() ){ ImagemapComponent comp = (ImagemapComponent)map.nextElement(); Polygon poly = comp.getPlacement(); ComponentHandle handle = comp.getComponentHandle(); String tooltips[] = comp.getTooltips(); //Status line will display a component name on click writer.print( "<AREA onclick=/"window.status='" ); writer.print( handle.getName() ); writer.print( "';return false;/" SHAPE=/"POLY/" COORDS=/"" ); for( int i=0; i<poly.npoints; i ++ ){ if( i!=0 ) writer.print( ", " ); writer.print( poly.xpoints[i] ); writer.print( ", " ); writer.print( poly.ypoints[i] ); } //Support Tooltips (using Internet Explorer syntax) writer.print( "/" HREF=/"/" ALT= /"" ); if( tooltips != null ) for( i=0; i<tooltips.length; i++ ){ if( i!=0 ) writer.print( "/n" ); writer.print( tooltips[i] ); } writer.println( "/">" ); } writer.println( "</MAP>" );
The sample code for using the Java API to create an imagemap produces an imagemap such as the following.
<IMG SRC="testmap.gif" USEMAP="#ELEMENTS" BORDER=NONE> <MAP NAME="ELEMENTS" > <AREA onclick="window.status='LegendText';return false;" SHAPE="POLY" COORDS="297, 468, 332, 468, 332, 453, 297, 453" HREF="" ALT= ""> <!--part of the map is omitted--> <AREA onclick="window.status='DataLine';return false;" SHAPE="POLY" COORDS="225, 358, 181, 322, 181, 309, 225, 345" HREF="" ALT= ""> <AREA onclick="window.status='DataLine';return false;" SHAPE="POLY" COORDS="181, 322, 167, 311, 167, 304, 170, 300, 181, 309" HREF="" ALT= "Value: 18.00"> <!--part of the map is omitted--> </MAP>