2016-07-23 69 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。 –