remove XYLineAnnotation on chartMouseClicked

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
r2112
Posts: 1
Joined: Fri Mar 16, 2012 8:54 pm
antibot: No, of course not.

remove XYLineAnnotation on chartMouseClicked

Post by r2112 » Fri Mar 16, 2012 9:17 pm

It´s removing annotations as a FIFO stack. And not the annotation that I click.
Thanks in advance.

Code: Select all

public void chartMouseClicked(ChartMouseEvent chartmouseevent) {  
    ChartEntity chartentity = chartmouseevent.getEntity();  
    XYPlot plot = (XYPlot) myChart.getChart().getPlot();  
    if (chartentity instanceof XYAnnotationEntity){  
        XYAnnotationEntity xyEntity = (XYAnnotationEntity) chartentity;  
        String tip = xyEntity.getToolTipText();  
        List<AbstractXYAnnotation> list = plot.getAnnotations();  
        for (AbstractXYAnnotation annot : list) {  
            if ((annot.getToolTipText()).equals(tip)) {  
                plot.removeAnnotation(annot);  
                break;  
            }  
        }  
    }  
}  

Locked