JFreeChart XYPlot XYImageAnnotation 鼠标点击监听器

JFreeChart XYPlot XYImageAnnotation mouse click listener

我有一个 JFreeChart 有 2 个子图 (XYPlot)。

我有 XYImageAnnotation 个我想变成按钮的东西,但我找不到一种方法来听鼠标点击任何注释。

你知道怎么做吗?

I have no idea how to listen [for] click from annotations

在您的 ChartMouseListener 中,您会得到一个 ChartMouseEvent。用它来得到 ChartEntity 那是 XYAnnotationEntity.

chartPanel.addChartMouseListener(new ChartMouseListener() {

    @Override
    public void chartMouseClicked(ChartMouseEvent cme) {
        ChartEntity ce = cme.getEntity();
        if (ce instanceof XYAnnotationEntity) {
            // handle the click
        }
    }
}

否则,查找您添加了注释的 XYItemEntity