【问题标题】:Jfree chart Find SubplotJfree 图表查找子图
【发布时间】:2011-12-16 09:04:45
【问题描述】:

作为一个问题,这听起来可能非常基本,但我被 JFreechart 的使用困住了。

让我列出我的问题:

  1. 我有一个 CombinedDomainXYPlot,我会在需要时向其中添加我的子图。
  2. 我使用了我的自定义 JPopup 菜单并包含一个菜单项,旨在为用户提供删除特定子图的工具
  3. 我假设可以使用主图的 findSubplot 方法找到子图。我能够获取鼠标位置,但无法使用 PlotRenderingInfo 作为输入所需的任何操作。

不胜感激。

【问题讨论】:

  • 我想找到一个组合域xyplot 的子图。我假设可以使用 findSubplot(PlotRenderingInfo info,Point2D source) 方法来完成。我能够找到 2DPoint,所以这不是问题。如何获取 PlotRendering 信息参数?

标签: jfreechart


【解决方案1】:

您可以使用getSubplots() 获得子图的List。要了解单击了哪个子图,请检查从ChartPanel 发送的ChartMouseEvent,如建议的here

附录:这是ChartMouseListener 的简单实现,将在单击时显示每个ChartEntity

ChartPanel panel = ...
panel.addChartMouseListener(new ChartMouseListener() {

    @Override
    public void chartMouseClicked(ChartMouseEvent e) {
        System.out.println(e.getEntity().getClass());
    }

    @Override
    public void chartMouseMoved(ChartMouseEvent event) {}
});

【讨论】:

  • 感谢@trashgod 的代码。我现在可以获得图表实体,并且我已经有了子图列表。我很困惑如何删除子图,因为上面的代码给了我图表实体。如上所述,我尝试使用getClass。我错过了什么?
  • 哦,解决了。 PlotEntity entity = (PlotEntity) event.getEntity(); XYPlot subplot = (XYPlot) entity.getPlot(); plot.remove(subplot); 其中plot 代表我的CombinedDomainXYPlot。感谢一百万@trashgod
  • 还有另一种简单的方法可以从任何地方调用...plot.findSubplot(chartPanel.getChartRenderingInfo().getPlotInfo(), chartPanel.getMousePosition()); 其中“chartPanel”是您的ChartPanel 对象
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多