我想建立一个使用机器学习算法进行数据分析的软件,我需要在图表中可视化数据进行预处理。我使用以下代码在jtable中显示数据:我使用jfilechooser打开文件并在jtable中显示数据,如下所示:
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);
之后,我想用类似于weka的条形图将表中的数据可视化,但是我找不到一个方法来实现这一点,我找到的方法是创建数据集并将其填充到代码中。
暂无答案!
目前还没有任何答案,快来回答吧!