Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

machine learning - how to visualize data from Jtable in java in NetBeans

I want to built a software for data analysis using machine learning algorithms and I need to visualize the data in charts for preprocessing. I use the following code to display data in the jtable: I use jfilechooser to open the file and display the data in a jtable as following:

JFileChooser Chooser = new JFileChooser();
FileNameExtensionFilter filter =new FileNameExtensionFilter ("open file 
","csv");
Chooser.setFileFilter(filter);
Chooser.showOpenDialog(null);
File f = Chooser.getSelectedFile();
if (f != null) {
   String filename1 = f.getAbsolutePath();
   filepath.setText(filename1);
} else {
  JOptionPane.showMessageDialog(this, "No File Selected");
}      
  filePath1 = filepath.getText();
 File file = new File(filePath1);
    //send data to the other tab 
jTable1.setModel(new DefaultTableModel(null,new String[] 
{"column1","column2","column3","column4"}));
     try {
        BufferedReader br = new BufferedReader(new FileReader(file));
        // get the first line
        // get the columns name from the first line
        // set columns name to the jtable model
        String firstLine = br.readLine();
        String[] columnsName = firstLine.split(",");
        
        DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
        model.setColumnIdentifiers(columnsName);
       attributesNum= columnsName.length;
        String st;
        String eachline;
        String[] cells;
       DefaultCategoryDataset bardataset =new  DefaultCategoryDataset();

        // there is a new line 
        while ((st = br.readLine()) != null) {
         // System.out.println(st); 
             eachline = st.trim();
            cells = eachline.split(",");
            //show each line in jtable
            model.addRow(cells);
                                                                              

after that I want to visualize the data in the table in a bar chart in away similar to weka but I couldn't find a method to do that what I found is methods to create dataset and fill it inside the code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...