Results 1 to 4 of 4
  1. #1
    niloR19 is offline Member
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Post 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;
    }
    }

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: java graph plot taking file data

    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.

  3. #3
    niloR19 is offline Member
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Default 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
    `````````````````````````````````````````````````` `

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,422
    Rep Power
    20

    Default Re: java graph plot taking file data

    Search the net for JFreeChart

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 11
    Last Post: 01-14-2012, 06:46 PM
  2. taking data from recent output file
    By sara12345 in forum New To Java
    Replies: 3
    Last Post: 01-05-2010, 11:48 PM
  3. How to plot graph in java for given samples
    By annesteve31 in forum New To Java
    Replies: 27
    Last Post: 11-29-2009, 09:27 PM
  4. i want plot realtime graph in java
    By santhosh_el in forum New To Java
    Replies: 3
    Last Post: 02-26-2009, 08:32 AM
  5. Plot 2D graph in Java from RS-232 data
    By spratana in forum Java 2D
    Replies: 4
    Last Post: 02-11-2009, 06:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •