import com.imsl.chart.*; import java.awt.Color; public class SamplePick extends JFrameChart implements PickListener { static private final double x[] = {0, 1, 2, 3}; static private final double y[] = {4, 1, 2, 5}; public SamplePick() { // Create a bar chart Chart chart = getChart(); AxisXY axis = new AxisXY(chart); Bar bar = new Bar(axis, x, y); bar.setBarType(Bar.BAR_TYPE_VERTICAL); bar.setLabels(new String[]{"A","B","C"}); bar.setFillColor(Color.blue); // Add the pick listener to the bar bar.addPickListener(this); // Add the mouse listener addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent event) { getChart().pick(event); } }); } public void pickPerformed(PickEvent event) { // Track the number of hits on this bar ChartNode node = event.getNode(); int count = node.getIntegerAttribute("pick.count", 0); count++; node.setAttribute("pick.count", new Integer(count)); // Change the bar's color depending on the number of times // it has been picked. Color color = ((count%2==0) ? Color.blue : Color.red); node.setFillColor(color); node.setLineColor(color); repaint(); } public static void main(String argv[]) { new SamplePick().setVisible(true); } }