Results 1 to 4 of 4
Thread: java graph plot taking file data
- 11-28-2011, 03:33 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 2
- Rep Power
- 0
java graph plot taking file data
hey i want to make a java interface which will read data from txt file and then will generate a graph using the data.my program is like this till date.i want your help.please help me.i am not able to do further. please please help me..!!
import java.io.*;
import java.util.*;
import java.util.StringTokenizer;
class file_test
{
String str = "";
FileInputStream fin;
DataInputStream in;
BufferedReader br;
StringTokenizer st;
int M, N; // column and rows
data[] d;
public file_test()
{
N = 0;
try
{
fin = new FileInputStream("data.txt");
in = new DataInputStream(fin);
br = new BufferedReader(new InputStreamReader(in));
}
catch(IOException ioe)
{
System.out.println("Exception while reading the file" + ioe);
}
try
{
while( (str = br.readLine()) != null)
{
M = 0;
str.trim();
st=new StringTokenizer(str,"\t");
M = st.countTokens();
N++;
}
System.out.println("No. of rows = " + N + " No. of columns = " + M);
d = new data[N];
for(int i=0; i < N; i++)
{
d[i] = new data();
d[i].no = -1;
d[i].y = new double[M];
}
fin.close();
try
{
fin = new FileInputStream("data.txt");
in = new DataInputStream(fin);
br = new BufferedReader(new InputStreamReader(in));
}
catch(IOException ioe)
{
System.out.println("Exception while reading the file" + ioe);
}
int i=0;
while(i < N)
{
d[i].no = i;
str = br.readLine();
str.trim();
st=new StringTokenizer(str,"\t");
int x = 0;
while(x < M )
{
// System.out.println(" " + st.nextToken());
d[i].y[x] = Double.parseDouble(st.nextToken());
x++;
}
i++;
}
for(i=0; i<N; i++)
{
System.out.println("Row " + d[i].no + " : ");
for(int j=0; j < M; j++)
{
System.out.print(" " + d[i].y[j]);
}
System.out.println();
}
fin.close();
}
catch(FileNotFoundException e)
{
System.out.println("File could not be found on filesystem");
}
catch(IOException ioe)
{
System.out.println("Exception while reading the file" + ioe);
}
}
public static void main(String args[])
{
file_test ft = new file_test();
}
class data
{
int no;
double[] y;
}
}
- 11-28-2011, 03:55 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,606
- Rep Power
- 5
Re: java graph plot taking file data
You will increase your chances of getting the help you want by asking a specific question. Where exactly are you stuck? And FWIW, use the code tags.i want your help.please help me.i am not able to do further
- 11-28-2011, 04:15 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 2
- Rep Power
- 0
Re: java graph plot taking file data
hey doWhile,
this very code of mine is able to read the data file.now i want to plot this values to a graph.how can i do this.
My data.txt file contain following data set-
1 2 3 4 56 7 78 9
3 5 7 8 91 4 42 4
`````````````````````````````````````````````````` `
- 11-28-2011, 06:56 PM #4
Similar Threads
-
How to plot graph in java with multiple lines for given samples (stored in arrays)?
By theWall in forum Java 2DReplies: 11Last Post: 01-14-2012, 06:46 PM -
taking data from recent output file
By sara12345 in forum New To JavaReplies: 3Last Post: 01-05-2010, 11:48 PM -
How to plot graph in java for given samples
By annesteve31 in forum New To JavaReplies: 27Last Post: 11-29-2009, 09:27 PM -
i want plot realtime graph in java
By santhosh_el in forum New To JavaReplies: 3Last Post: 02-26-2009, 08:32 AM -
Plot 2D graph in Java from RS-232 data
By spratana in forum Java 2DReplies: 4Last Post: 02-11-2009, 06:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks