JFreeChart - remover XYLineAnnotation

0 respostas
R

Consigo inserir XYLineAnnotations com o mouse.
Mas estou com dificuldade para remover a annotation na qual estou clicando. A cada clique, o sistema remove um annotation como se fosse uma pilha FIFO. E não no objeto que estou clicando.

Agradeço a ajuda.

public void chartMouseClicked(ChartMouseEvent chartmouseevent) {
		ChartEntity chartentity = chartmouseevent.getEntity();
		XYPlot plot = (XYPlot) myChart.getChart().getPlot();
		System.out.println(chartentity.getClass());
		if (chartentity instanceof XYAnnotationEntity){
			XYAnnotationEntity xyEntity = (XYAnnotationEntity) chartentity;
			String tip = xyEntity.getToolTipText();
			System.out.println("tooltip selected: " + tip);
			List<AbstractXYAnnotation> lista = plot.getAnnotations();
			for (AbstractXYAnnotation anot : lista) {
				System.out.println("cada: " + anot.getToolTipText());
				if ((anot.getToolTipText()).equals(tip)) {
					System.out.println("removeu: " +anot.getToolTipText());
					plot.removeAnnotation(anot);
					break;
				}
			}
		}
	}
Criado 16 de março de 2012
Respostas 0
Participantes 1