繁体   English   中英

如何使用JFreeChart在饼图中突出显示或聚焦特定饼图部分

[英]How to highlight or focus particular pie section in a pie chart using JFreeChart

我正在使用Swing应用程序中的JFreeChart开发一个简单的饼图。 基于关键事件,我想要关注或突出显示饼图的特定饼图部分。 知道JFreeChart中的api提供了哪些功能吗?

您可以在PiePlot上使用setExplodePercent() ,就像它们在此处所示

JFreeChart chart = ChartFactory.createPieChart(…);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setExplodePercent(KEY, PERCENT);

我需要一些方法来设置边框或根据某些事件将焦点设置到该部分,例如鼠标悬停在特定部分上。

我试图@ trashgod的想法加入了ChartMouseListenercreateDemoPanel()PieChartDemo1 将鼠标悬停在每个部分上以查看效果。 尝试不同的percent值以获得所需的效果。

饼形图

panel.addChartMouseListener(new ChartMouseListener() {

    private Comparable lastKey;

    @Override
    public void chartMouseMoved(ChartMouseEvent e) {
        ChartEntity entity = e.getEntity();
        if (entity instanceof PieSectionEntity) {
            PieSectionEntity section = (PieSectionEntity) entity;
            PiePlot plot = (PiePlot) chart.getPlot();
            if (lastKey != null) {
                plot.setExplodePercent(lastKey, 0);
            }
            Comparable key = section.getSectionKey();
            plot.setExplodePercent(key, 0.10);
            lastKey = key;
        }
    }

    @Override
    public void chartMouseClicked(ChartMouseEvent e) {
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM