Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Bar chart with J table

Have Programming Question? Ask it here!
 
 
 


Nikica
Bar chart with J table
0 Answer(s)      a year and 10 months ago
Posted in : Java Beginners


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);

}

}


Advertisement
View Answers

Related Tutorials/Questions & Answers:
Bar Chart in JSP - JSP-Servlet
Bar Chart in JSP  Hi I am creating Bar chart using Jfree charts in JSP. Please advise me how to customize it. Like controlling the colors, width for each bar, showing values above the bar .  hi friend, Use
JFree 3D Bar Chart not displaying in JSP - Java3D
JFree 3D Bar Chart not displaying in JSP  Hi I am trying to run JFree 3D bar chart written in your site under link: http://www.roseindia.net/chartgraphs/3Dbarchart-in-jsppage.shtml This is not working. PNG file
Advertisements
JFreechart Stacked Bar Chart
JFreechart Stacked Bar Chart JFreechart provides a way to create various... Bar Chart. This chart actually displays the result of multiple queries stacks... = ChartFactory.createStackedBarChart( "Stacked Bar Chart", "Games", "No. of students
Create Bar Chart with database values
Create Bar Chart with database values In this section, you will learn how to create a bar chart by retrieving the values from the database. For this purpose... createBarChart3D() of the class ChartFactory creates a vertical 3D bar chart. Now
j - Java Beginners
(); for (int j = 0; j < selected.length; j++) { selected1.add(selected[j
Search bar application
Search bar application In this tutorial, will be creating a Search screen, which have a table view with a search bar. Table should display all the data... that will be displayed in table NSMutableArray *searchedData;  //will be storing data
Delete and add row from Table View iPhone
on Navigation bar. Will add this to insert object into the Table View and setting title for the table and also the Button on Bar button is added with the title...Delete and add row from Table View iPhone In this tutorial will learn how
How to Connect J ComboBox with Databse - Java Beginners
How to Connect J ComboBox with Databse  How to Connect J ComboBox with Databse  Hi Friend, Do you want to get JComboBox values from database?Please clarify this. Thanks
display combination of a stacked area chart and line chart in one iframe using jfree - JSP-Servlet
display combination of a stacked area chart and line chart in one iframe using jfree  hello i have a problem related to jfree chart, i want to display combination of a stacked area chart and line chart in one iframe
chart tutorial - Java3D
chart tutorial  Hi I need a JFree Chart class library in order to design a chart with java  Hi friend, For JFree Chart class library... information,Tutorials and Examples on JFree Chart visit to : http://www.roseindia.net
Connect J ComboBox with Databse - Java Beginners
Connect J ComboBox with Databse  Hello Sir I want To Connect MS Access Database with JComboBox , when I Select any Item from Jcombobox Related Records will Display in to JTextBox eg when i select MBA then fees ,Duration
surface chart - Java3D
surface chart  i have to make a surface chart of a piece of land with data given for each point in the xy plane....the chart should be such that the areas with different data range should show up in different colour. seriously
make chart or graph from database - Java Beginners
make chart or graph from database  d, I want to ask about how to make a chart or graph. First i have Table name= "customer" and field =(cust_id... customer come to me. in this chart have two values nm_id and date. Please give
Progress Bar - Swing AWT
Progress Bar  Hey if possible plz help me in making the following program work... i m using threads in order to make the progress bar auto increment..." is for manual updation of progress bar.. import java.awt.*; import javax.swing.
JFREE chart - Java Beginners
..thanks,i want my chart to display dynamically from my database  Hi... database on your chart
chart library - Java3D
chart library  hi Where can i download jfreechart-1.0.4-demo.jar and jcommon-1.08.jar files  Hi friend, For download jfreechart-1.0.4-demo.jar and jcommon-1.08.jar files visit to : http://www.roseindia.net
Pie Chart - Java Beginners
Pie Chart  How to Draw a Pie chart using graphics in java  Hi friend, I am going to post complete running code. import java.awt.... ChartPanel(values, names, "Simple Pie Chart")); WindowListener wndCloser = new
To read a excel with chart - Java Beginners
To read a excel with chart   Hi, I need to read the data in an excel which is in chart format using java. when I directly change the extention of excel file to CSV i am not getting the data in the chart.Please help me
Create Pie Chart using database values
Create Pie Chart using database values Java provides JFreeChart library which... bar charts, line charts in the previous sections. Here we are going to create a pie chart by retrieving the values from the database. Here is the code
java j s p and servlets - Servlet Interview Questions
java j s p and servlets  how to handle data from a select box store them back to database through servlet  Hi friend, For solving the problem visit to : http://www.roseindia.net/servlets/SelectColor.shtml
Chart Series Class in Flex4
Chart Series Class in Flex4: The chart series classes are used for render a data in a chart control. The series classes are used... chart type has a its own series class. for example, Bubble chart has
Chart Event in Flex4
Chart Event in Flex4: Chart uses the chartEvent when you perform the operation click and doubleclick on the chart. This event is the part of chart package... on the chart item the ChartEvent will not triggered. Example: <?xml
HEAP table
HEAP table  hiii, What is HEAP table?   hello, This type of table is stored in the memory. Speed of execution of this table is very commendable
Swings Menu Bar - Java Beginners
Swings Menu Bar  Hello, I created a menu bar using Java Swings... n New Record, Edit Record etc are the menu items. Now, I want to display... bar... How to do this..?? or atleast what to use to get this..??  Hi
Chart Item Event in Flex4
Chart Item Event in Flex4: Chart uses the ChartItemEvent when you perform the operation click on the chart Item. This event is the part of chart package... on the chart the result will display data not found. Example:  
center a table
center a table  How do I center a table
Using Progress Bar in java apps
Using Progress Bar in java apps  Please, i am writing a program in java to read a file, perform some operation on each line of the file and them write back to another file. I would like to know how to use a progress bar to mark
hybrid graph (jfree chart) - Swing AWT
hybrid graph (jfree chart)  hello i have a problem related... of stacked area chart and Line chart in one frame. Plese anybody help me out... and explain in details For more information on chart visit to : http
Formatting Legend in Chart in Flex4
Formatting Legend in Chart in Flex4: In this section we will discuss the formatting of the Legend in the Chart control. You can change the formatting... property for change the formatting of legend in the chart control. Example
MultipleAxes in Chart in Flex4
Multiple Axes in Chart in Flex4: When we use different(Unmatched) data in single chart so it will not be possible to represent multiple series in a single chart. For solving this problem we use multiple axes in a single chart
progress bar in google map - Development process
progress bar in google map   in my google map i want a progress bar... are loaded on the map.  Hi Nikhil, This is simple progress bar code...; private JPanel topPanel; public ProgressBarDemo(){ setTitle("Progress Bar
Chart Effect in Flex4
Chart Effect in Flex4: Chart uses the standard Flex effect like Zoom and Fade. There are some standard effect for chart series which is: SeriesInterpolate... package. The base class for chart effect is SeriesEffect. You can triggered
Copy a Html chart into PPT - Java Beginners
Copy a Html chart into PPT  Hi Experts, i am facing with a problem without solution. I have a Html site and would like to write a code so that by clicking on a button the graph will be copied in an active ppt. Could you
Regarding Gantt chart generation - Java Beginners
Regarding Gantt chart generation  how to generate a jdbc gantt chart..., To create a simple Gantt chart, try the following code: import...; JFreeChart chart = ChartFactory.createGanttChart( "Gantt Chart
Extjs Table Sorting
Extjs Table Sorting  how is it possible to do the table sort in extjs
Multiple Data Series in Chart in Flex4
Multiple Data Series in Chart in Flex4: In This example you can see how we can use multiple data series in a single chart. Every chart has a its own data...="Multiple Chart Series Example" width="659" height
Searching a tex on a table in java! - Java Beginners
Searching a tex on a table in java!  i have a table which contains several data. using a textfield the item hat i search must be selected and will show with using a scroll bar.... how should i do this.... tnx for the response
iPhone Tab Bar with Segmented Controller
iPhone Tab Bar with Segmented Controller  In this tutorial will learn how to use the two controller at the same time, Tab bar is used to show... and on that will add Tab bar controller and in that tab bar controller view
Data types in a table
Data types in a table  hii, What are the data types allowed in a table?   hello,, These are the data types in table:- VARCHAR2, CHAR... types in table:- VARCHAR2, CHAR, NUMBER, RAW, DATE, LONG and LONG RAW
Table refresh with ajax - Ajax
Table refresh with ajax  I am using jsp/html in my code. Is it compulsory that i have to use a servlet to implement table refresh using ajax? Or jsp also would work? Rajatha
Chart Style in Flex4
Chart Style in Flex4: In this section we will discuss the chart style. You can... the style of the chart. Example: <?xml version="1.0"...="Chart Style Example" width="713" height="521
iPhone Simple Table View
Simple Table View In this tutorial will learn how to use Table View and also how to add object to table view, to insert the object into the table view we have to take an array and through that will add or insert the object into the Table
Create Chart using Action script in Flex4
Create Chart using Action script in Flex4: In this section you will see how we can create a chart using action script. we have to need some classes in action script For create a chart. They are following: import
editing cell in a table - JDBC
editing cell in a table  how can i edit a cell in a table and save the change to a database  Hi Friend, Try the following code: 1)updateDatabase.jsp RollNo Name Class "> "> ">
Table generation error - EJB
Table generation error  Hi friends I am using EJB3.0 with sun java... an EJB it gives the following exception and doesnt generate any table... "CREATE TABLE BookShop (ID INTEGER NOT NULL, BOOKNAME VARCHAR(255), AUTHOR VARCHAR
mysql table construction - SQL
mysql table construction  In MySql there is no pivot function. using a function or Stored Procedure, I want to loop through a column of data and create a another table that uses the row value as Column labels from the row
updating a table in a database - SQL
updating a table in a database  give me complete source code in java to execute the sqlquery such that (update table_name set phone no=? where cous_id=?). or in simple way give me source code to update my table in MsAccess
Create Multiplication Table from 1 to 10
Create Multiplication Table in Java In this section, you will learn how to create multiplication table from 1 to 10. For this purpose, we have created... of two variables i and j to the array[i][j]. Here is the code
Skinning Data Item in Chart in Flex4
Skinning Data Item in Chart in Flex4: In this section you can see how we can provide the skin to data item in chart control. We will use the itemRenderer... the representation of data item. we use the image for showing the data values in the chart
Advertisements
 

 

 

DMCA.com