Bar chart with J table

Bar chart with J table

Hi I'm new in Java and I have a application that reads multiple text files and displays them in a Jtable.So can you please tell me how can I make a bar graph that will display the data from my table.I tried using the code from your page (http://www.roseindia.net/chartgraphs/bar-chart.shtml) but I couldn't make it work. Thanks in advance.

Here is my code

package table2;

import java.io.*; import java.awt.*; import java.util.*; import javax.swing.*; import java.awt.event.*; import javax.swing.table.*; import java.awt.color.*; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset;

public class InsertFileDataToJTable extends AbstractTableModel {

Vector data;
Vector columns;

public InsertFileDataToJTable() {
    String line;
    data = new Vector();
    columns = new Vector();
    columns.addElement("ID");
    columns.addElement("RSSI");

    String path = "C:/Users/Nikica/Desktop/text files";

    String files;
    File folder = new File(path);
    File[] listOfFiles = folder.listFiles();

    for (int y = 0; y < listOfFiles.length; y++) {
        if (listOfFiles[y].isFile()) {
            files = listOfFiles[y].getName();
            if (files.endsWith(".txt") || files.endsWith(".TXT")) {

                System.out.println(files);
                //    TreeMap<String, Integer> frequencyMap = new TreeMap<String, Integer>(); 


                File textFile = new File(folder.getAbsolutePath() + File.separator + files);
                try {

                    FileInputStream fis = new FileInputStream(textFile);
                    // DataInputStream in = new DataInputStream(fis);
                    BufferedReader br = new BufferedReader(new InputStreamReader(fis));


                    int i = 0;
                    while ((line = br.readLine()) != null) {
                        if (line.startsWith("17/10/2012 10:00:06.67 [RX] - E usbR<LF>") || line.startsWith("E qEnd<LF>") || line.startsWith("00<LF>")) {
                            continue;
                        }
                        String ID = line.substring(0, 12);
                        String RSSI = line.substring(13, 15);
                        data.addElement(ID);
                        data.addElement(RSSI);

                    }

                    br.close();

                    /*
                     * FileInputStream fis = new FileInputStream("ard.txt");
                     * BufferedReader br = new BufferedReader(new
                     * InputStreamReader(fis)); StringTokenizer st1 = new
                     * StringTokenizer(br.readLine(), "-"); while
                     * (st1.hasMoreTokens()) {
                     * columns.addElement(st1.nextToken()); } while ((line =
                     * br.readLine()) != null) { StringTokenizer st2 = new
                     * StringTokenizer(line, "-"); while
                     * (st2.hasMoreTokens()) {
                     * data.addElement(st2.nextToken()); } } br.close();
                     */
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        }
    }
}

public int getRowCount() {
    return data.size() / getColumnCount();
}

public int getColumnCount() {
    return columns.size();
}

public Object getValueAt(int rowIndex, int columnIndex) {
    return (String) data.elementAt((rowIndex * getColumnCount())
            + columnIndex);
}

public static void main(String s[]) {
    InsertFileDataToJTable model = new InsertFileDataToJTable();
    JTable table = new JTable();
    table.setAutoCreateRowSorter(true);
    JTableHeader header = table.getTableHeader();
    table.setModel(model);
    table.getColumnModel().getColumn(0).setHeaderValue("ID");
    table.getColumnModel().getColumn(1).setHeaderValue("RSSI");
    table.getTableHeader().resizeAndRepaint();

    JScrollPane scrollpane = new JScrollPane(table);
    JPanel panel = new JPanel();
    panel.add(scrollpane);
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel, "Center");
    frame.pack();
    frame.setVisible(true);

}

}

View Answers

Ads









Related Tutorials/Questions & Answers:
Bar chart with J table
Bar chart with J table  Hi I'm new in Java and I have a application... tell me how can I make a bar graph that will display the data from my table.I tried using the code from your page (http://www.roseindia.net/chartgraphs/bar
bar chart
bar chart  how to create a bar chart from values of the database and the string value should be the entities of the database??plzz help..needed badly
Advertisements
how to fetch data from mysql database table and draw a bar chart on that data using in jsp
how to fetch data from mysql database table and draw a bar chart on that data using in jsp  how to create bar chart fetch data from mysql database using in jsp.please give me a right code. yhanks in advance
Bar Chart
Bar Chart  hi...... Thanks 4 ur help for the bar graph creation i have got what i wanted. But now want to ask that in that bar graph i want multiple bar on one value means I want to create a graph where on my x-axis i have
Bar chart implementation in PHP
Bar chart implementation in PHP  How to implements reports in bar graphs by using PHP
Stacked Bar Chart
Stacked Bar Chart  How to display a stacked bar chart using java from the values stored in the ms access database?Plzz help..its urgent
Bar Chart
Bar Chart       In this section we are providing you an example to create a Bar Chart. Description of Program  For creating a Bar chart we use the object
Bar Chart
Bar Chart       This section illustrates you how to create bar chart using html in jsp. To draw a bar chart, we have used html tags. In this, firstly
Table-chart selection
Table-chart selection  Hai, Our application has pdf download.The pdf file has chart and table..Now the problem is user choose only table option but table and chart download..i want table only..the coding was given below
Bar Chart using JSP and tooltip to be implemented
Bar Chart using JSP and tooltip to be implemented  Hi Deepak, I have generated a bar chart in JSP using JFreeCharts but I could not get the tool tip for that. Please any one suggest me how to do that or provide some code. Help
How to create bar chart using database values
How to create bar chart using database values  How to create bar chart using database values i.e excellent,good,average fields using jsp?It is like opinion poll.I want to show how many votes are came for excellent,good,average
3D Bar Chart
3D Bar Chart       In this section we are providing you an example to create a 3D Bar Chart. Description of Program  For creating a 3D Bar chart we use the object
create bar chart in jsp using msaccess database
create bar chart in jsp using msaccess database  thanks for reply... ChartFrame("Bar Chart",chart); frame1.setVisible(true); frame1.setSize(350,450); %> Here student is our dsn and chart is table
Bar Chart in Java
Bar Chart in Java      ... to draw simple bar chart in Java. A bar chart (bar graph) is a way of comparing two... chart in Java. To draw a bar chart, the variables minvalue, maxvalue of double type
how to create a bar chart in jsp by fetching value from oracle databse?
how to create a bar chart in jsp by fetching value from oracle databse?  i want to show the population of various states in a bar chart in my jsp page by fetching the data from my oracle table. i am using my eclipse as my IDE
create bar chart in jsp using msaccess database
create bar chart in jsp using msaccess database  type Exception report message description The server encountered an internal error... Foundation\Tomcat 5.0\work\Catalina\localhost\chetana\org\apache\jsp\bar_jsp.java:57
Stacked Bar Chart Example using JFreeChart
Stacked Bar Chart Example using JFreeChart... a Stacked bar chart using JFreeChart. Bar chart will represent scores of two team... to create stacked bar chart for given values. It  takes title, domain axis
Stacked Bar Chart using JFreeChart
Stacked Bar Chart using JFreeChart   ... bar chart using JFreeChart. In the code given below we have extended class.... createStackedBarChart(): This method is used to create stacked bar chart for given values
Stacked 3d Bar Chart Example using JFreeChart
Stacked 3d Bar Chart Example using JFreeChart... a Stacked 3d bar chart using JFreeChart. Bar chart will represent the score... is used to create stacked bar chart for given values. It takes title, domain
Java program that inputs a document and then outputs a bar-chart pit
Java program that inputs a document and then outputs a bar-chart pit  Hello, I am new to Java and would like to see a Java Program that inputs a document and then outputs a bar-chart plot relative to the frequencies of each
Create a bar chart in JSP page using JFreeChart
Create a bar chart in JSP page using JFreeChart... to create a bar chart in JSP page using JFreeChart. Code given below creates a bar chart...(): This method is used to save chart in to png format. jspbarchart.jsp
how to create bar chart in jsp using msaccess database
how to create bar chart in jsp using msaccess database  type Exception report message description The server encountered an internal error... Foundation\Tomcat 5.0\work\Catalina\localhost\chetana\org\apache\jsp\bar_jsp.java
Horizontal Bar Chart Example using JFreeChart
Horizontal Bar Chart Example using JFreeChart... a Horizontal bar chart using JFreeChart. This example showing you match.... createBarChart():  This method is used to create bar chart for given values
Draw Statistical chart in jsp
chart in jsp by getting values from database.. To draw a bar chart, we have... a vertical 3D bar chart. The class PlotOrientation is used to indicate... Draw Statistical chart in jsp   
Create a 3D bar chart in JSP page using JFreeChart
Create a 3D bar chart in JSP page using JFreeChart... to create a 3D bar chart in jsp page using JFreeChart. Code given below creates a bar chart of scores of two teams in matches. In the code given below
Bar graph
Bar graph  How to include a bar chart in iPhone sdk
how to generate a bar chart on a JSP PAGE using the arraylist object passed form the servlet.(using jfreechart)
how to generate a bar chart on a JSP PAGE using the arraylist object passed form the servlet.(using jfreechart)  I have created a servlet.In this,i have retrieved a record from MS Access database in an arraylist i.e. my arraylist
java bar charts and jsp
java bar charts and jsp  Hi, Can any one help me out in how to create java bar charts using jsp with the help of data base table values? thanks.../jsp/draw-statistical-chart-jsp.shtml
draw chart in web application
draw chart in web application  how to draw bar chat from the record store in database? i.e. draw the bar chart according to selected record
Bar charts and jsp
Bar charts and jsp  Hi, How to generate Dynamic Bar Chart Images using jsp with placing any image location in weebroots? Thanks in advance
java with jsp and dynamic database retrival for bar charts
java with jsp and dynamic database retrival for bar charts  Hi, I am having a table name tablelogin,it consists of columns userid,logintime,sessionid,ip_address,logout. so,can any one help me out how to get the bar chart

Ads