簡體   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