mouse Clicks on axes

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
avanidhar
Posts: 16
Joined: Wed Jun 11, 2008 10:47 pm

mouse Clicks on axes

Post by avanidhar » Mon Apr 27, 2009 3:27 pm

Hi all,

I am using
JFreechart 1.0.13 and am stuck at a point where I need to handle mouse click events on the axes. Is there a way to do this in the latest JFreeChart version?? Please do let me know.

Avanidhar

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: mouse Clicks on axes

Post by paradoxoff » Mon Apr 27, 2009 7:32 pm

Create a ChartMouseListener and add that to the ChartPanel.
In the chartMouseClicked(ChartMouseEvent event) method, get the ChartEntity of the event (chartMouseEvent.getEntity()), check whether the ChartEntity is an instance of AxisEntity, and if yes, get the axis (axisEntity.getAxis()).

avanidhar
Posts: 16
Joined: Wed Jun 11, 2008 10:47 pm

Re: mouse Clicks on axes

Post by avanidhar » Tue Apr 28, 2009 4:06 pm

thanks paradoxoff,

when i try to do as such

Code: Select all

ChartEntity entity = event.getEntity();
            System.out.println(event.getEntity().toString());
i get a null pointer exception. It seems like the event.getEntity() method is returning a null pointer. any reasons why this could be happening?

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: mouse Clicks on axes

Post by paradoxoff » Tue Apr 28, 2009 11:12 pm

Difficult to say w/o source code. Can you check whether the entity is indeed null? If that is the case, you might have simply missed the axis.

Locked