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;
}
}
Re: java graph plot taking file data
Quote:
i want your help.please help me.i am not able to do further
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.
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
`````````````````````````````````````````````````` `
Re: java graph plot taking file data
Search the net for JFreeChart
db