2012-05-03 76 views
1

我在具有多個類別標籤的Swing GUI中使用JFreeChart條形圖表。每個標籤都有幾個子類別標籤。有很多酒吧。因此每個人都很小,幾乎看不到。我希望能夠放大特定類別。選擇條形圖類別標籤

是否可以使類別標籤可點擊?例如,通過添加一個監聽器? 然後,我將點擊一個類別標籤,並將顯示的圖表設置爲僅顯示該類別。

如果不是的話,還有什麼可以讓酒吧變得更加明顯的另一種解決方案?

回答

1

最簡單的方法是在您的ChartFactory.createBarChart()中啓用工具提示。或者,使用ChartMouseListener(如here)執行一些其他操作。

編輯您的問題包括sscce可能有助於建議使用哪種方法。

2

爲鼠標聽者本人所使用的僞代碼:

chartPanel.addChartMouseListener(new ChartMouseListener() { 

    @Override 
    public void chartMouseClicked(ChartMouseEvent e) { 
    if (e.getEntity().getClass() != CategoryLabelEntity.class) { 
     return; 
    } 

    CategoryLabelEntity entity = (CategoryLabelEntity) e.getEntity(); 
    String category = (String) entity.getKey(); 

    //Using another dataSet, create a zoomedInChart 
    //composed only of values from that dataset 
    chartPanel.setChart(zoomedInChart); 
    } 

    @Override 
    public void chartMouseMoved(ChartMouseEvent e) { 
    // do nothing 
    } 

}); 
+0

1'setMouseWheelEnabled()'也可以是值得期待。 – trashgod