Using MouseClick Event on Line Chart Graph

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
civi
Posts: 7
Joined: Sun Feb 17, 2008 6:07 pm

Using MouseClick Event on Line Chart Graph

Post by civi » Wed Feb 20, 2008 2:17 am

I´m working on Line Chart Graph in JApplet.

I would like to open a Menu when clicking on a line point of ChartPanel

I try the following:

Code: Select all

class ChartApplet extends JApplet { ....
chartPanel.addChartMouseListener(New TestClass());
....

public class TestClass implements ChartMouseListener {


public void chartMouseClicked(ChartMouseEvent arg0) {

//I can use:

arg0.getChart()...
arg0.getEntity()...
arg0.getSource()..
arg0.getTrigger()..

}
but these methods doesn´t work since XYSeries Object it not recognize when the mouse click on line Graph

Can anybody help me to developer an Event that start up when clicking exactly on a Line Graph of ChartPanel? The above method mouseClicked of interface ChartMouseListener works when click in ALL Point of ChartPanel.

Please help me! its very important for me.

Best Regards

Cividanes

civi
Posts: 7
Joined: Sun Feb 17, 2008 6:07 pm

Post by civi » Wed Feb 20, 2008 2:40 am

for example:

Code: Select all

public void chartMouseMoved(ChartMouseEvent event) {
    //put your handling code here to handle mouse movement events
        ChartEntity entity = event.getEntity();
        //the above line will get the entity that is below the mouse.
       
        if ((entity instanceof XYItemEntity)) {
    //now we check what type of entity it is.
    //in my case im just checking if the mouse is over
    //any Datapoint on my chart. but you should be
    //able to extend this to any type of chart entity
            XYItemEntity ent = (XYItemEntity) entity;
            serindex = ent.getSeriesIndex();
            itemindex = ent.getItem();
    //now we actually have the series and item index of the data value
    //being pointed to by the mouse.
    //in a category chart you would get the series key and category key etc
    //now you may get the data from your dataset using these indexes
    //and do some processing:
            lblDisplay.setText("at x = "
                                        + mydata.getXValue(serindex,itemindex)
                                        + "  the value of y is : "
                                        + mydata.getYValue(serindex,itemindex));
        } //end if
    }
this above code line get XYSeries just if a click XYItemEntity (items of line graph), i need get when clicking just on line graph.

Please, Anybody could help me ?

Best Regards

Cividanes

Locked