2016-07-23 71 views
0

我有一個jtable我想顯示absciss中的字符列我試着通過把每列放在一個數組中,但它沒有顯示任何東西,當我調試它沒有進入例外,並且在CONSOL中沒有消息。由java中的jtable值填充條形圖

public void Graph() { 
    try { 
     DefaultCategoryDataset base = new DefaultCategoryDataset(); 

     Character[] letters = new Character[table.getRowCount()]; 
     Integer[] frequences = new Integer[table.getRowCount()]; 

     int i; 
     for (i = 0; i < table.getRowCount(); i++) { 
      letters[i] = (Character) table.getValueAt(i, 0); 
      frequences[i] = (Integer) table.getValueAt(i, 1); 
      base.setValue(frequences[i], "Fréquences", letters[i]); 
     } 

     JFreeChart graph = ChartFactory.createBarChart3D(
       "Diagramme des Fréquences",//titre 
       "Lettres", //abscisses 
       "Fréquences", //ordonnées 
       base, //data 
       PlotOrientation.VERTICAL, 
       false, //legende 
       true, //tooltips 
       false //URLs 
     ); 
     ChartPanel Panel = new ChartPanel(graph); 
     panelGraph.removeAll(); 
     panelGraph.add(Panel, BorderLayout.CENTER); 
     panelGraph.validate(); 
     CategoryPlot p = graph.getCategoryPlot(); 
     // set the range axis to display integers only... 
     final NumberAxis rangeAxis = (NumberAxis) p.getRangeAxis(); 
     rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 
    } catch (Exception e) { 
     JOptionPane.showMessageDialog(null, e); 
    } 
} 

運行,但圖中沒有出現的時候JTable中填充

+0

執行它請編輯你的問題,包括一個[mcve],它顯示你當前的方法。 – trashgod

回答

0

你可以嘗試使用甲骨文實現條形圖的JavaFX中8: Tutorial

如果你不希望使用JavaFX 8爲您的整個應用程序,你也可以在Swing中使用JFXPanelTutorial

+0

我不知道什麼是javaFX技術我在java中是初次嘗試,但我嘗試了其他的東西,我從hashmap提取數據到2個數組,並嘗試填充圖,但我有ArrayIndexOutOfBoundsException –

+0

http://docs.oracle .com/javase/8/javafx/get-started-tutorial/jfx-overview.htm#JFXST784這應該解釋什麼是JavaFX。簡要說明:自Java 8以來,建議用戶創建用戶界面。它的前身是Swing,我猜你正在使用它。 – SilverMonkey

+0

好的謝謝,我會看到,是的,我正在使用swing和awt。 –