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
Related Tutorials/Questions & Answers:
Bar chart with J tableBar 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 chartbar 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 ChartBar 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
Stacked Bar ChartStacked
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 in JSP - JSP-ServletBar 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
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 selectionTable-
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 implementedBar 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 valuesHow 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
JFree 3D Bar Chart not displaying in JSP - Java3DJFree 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 ChartJFreechart 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
create bar chart in jsp using msaccess databasecreate
bar chart in jsp using msaccess database type Exception report
message
description The server encountered an internal error...\work\Catalina\localhost\chetana\org\apache\jsp\
bar_jsp.java:57: cannot find symbol
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
Create Bar Chart with database valuesCreate
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 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...(): This method is used to create stacked
bar chart for given values. It takes
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 databasehow to create
bar chart in jsp using msaccess database type Exception report
message
description The server encountered an internal error...\Tomcat 5.0\work\Catalina\localhost\chetana\org\apache\jsp\
bar_jsp.java:61: cannot
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... createBarChart3D() creates a vertical 3D
bar chart.
The class PlotOrientation is used.../jsp/bar.jsp
to the address
bar and hit enter. The image of
chart is
displayed
Bar graphBar graph How to include a
bar chart in iPhone sdk
draw chart in web applicationdraw
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
java bar charts and jspjava
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
Bar charts and jspBar charts and jsp Hi,
How to generate Dynamic
Bar Chart Images using jsp with placing any image location in weebroots?
Thanks in advance
pie chartpie chart how to create pie
chart using struts2
Pie chartPie chart hi.................
In my project i want to create a pie-
chart by taking values at run time. As want to display it in pie
chart form....
Java Swing PIE
Chart JFree chart package error the jcommon jar file and jfree jar file for the
bar chart code. but now its giving...JFree
chart package error hi,
I had asked u abt the jfree
chart package and done what u have said. Its working but its giving me error that some
ModuleNotFoundError: No module named 'j'ModuleNotFoundError: No module named '
j' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
j'
How to remove the ModuleNotFoundError: No module named '
j' error
tabletable multiplicatyion
table Read Excel file and generate bar graph the data of excel file, we have generated a
bar
chart. The given code uses Apache...;, list1.get(
j).toString());
}
JFreeChart
chart = ChartFactory.createBarChart("...Read Excel file and generate
bar graph
In this tutorial, you will learn how
TABLE TABLE Why doesn't <
TABLE WIDTH="100%"> use the full browser width
Bar Chart Example using JFreeChart Bar Chart Example using JFreeChart
...
chart using JFreeChart.
Code given below creates a
bar chart of scores of two teams...():
This method is used to create
bar chart for given values. It
TableTable How i generate
table in showMessageDialog. I want that i creat a
table and run in showMessageDialogeprint("cprint("code sample");ode sample
Chart & Graphs Tutorials in Java.
Bar Chart Example
In this section we are providing you an example to create a
Bar Chart.
3D
Bar Chart Example
In this section we are providing you an example to create a 3D
Bar Chart.