how to listen for clicks in Java (JFreeChart) using events?

You can use addChartMouseListener() to add a ChartMouseListener to your ChartPanel. For example, in BarChartDemo1, add the following:

chartPanel.addChartMouseListener(new ChartMouseListener() {

    public void chartMouseClicked(ChartMouseEvent e) {
        System.out.println(e.getEntity());
    }

    public void chartMouseMoved(ChartMouseEvent e) {}

});

Leave a Comment