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



Home Answers Viewqa Java-Beginners Bar chart with J table
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Nikica
Bar chart with J table
0 Answer(s)      a year and 11 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 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
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 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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   
Bar graph
Bar graph  How to include a bar chart in iPhone sdk
J
J
 

 

 

DMCA.com