Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: How to plot line graph using jfreechart reading from text file

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to plot line graph using jfreechart reading from text file

    hello,
    how to plot graph using jfreechart by extracting date format i.e yyyy-mm-dd hh:mm:ss:SS (in x-axis) and kilobyte(in y-axis) from text file.

    the following code contains code for plotting graph for double values.but how to do for date formats versus kilobyte which is mentioned above.am in trouble in this please help us .
    Thanks in advance

    import java.io.*;
    import java.util.*;//Scanner is included
    import org.jfree.chart.*;
    import org.jfree.chart.plot.PlotOrientation;
    import org.jfree.data.category.DefaultCategoryDataset;
    import org.jfree.data.general.DefaultPieDataset;
    import org.jfree.data.xy.*;
    import org.jfree.data.*;
    public class Plot_1
    {
    static Scanner scanner;
    static XYSeries series;
    //static File file;
    public static void main(String[] args)
    {
    plotResult();



    }//end of main





    //**********



    //Method that reads in an external file with numbers (doubles)

    //and plots the content in a line chart using JFreeChart





    public static void plotResult() {



    //Read in the file "calculation.txt" using Scanner and call hasNextDouble on it



    try {

    int index = 0;



    File file = new File("data.txt");

    series = new XYSeries("Pk");

    scanner = new Scanner(file);

    // Scanner scanner = new Scanner(file);

    while (scanner.hasNextDouble()) {

    series.add(index++,scanner.nextDouble());

    }

    scanner.close();

    }

    catch (FileNotFoundException e) {
    e.printStackTrace();

    }





    //Round off the doubles to two decimals - not done yet







    //Plot the line chart







    /*

    XYSeries series = new XYSeries("Pk");

    series.add(1, 0.8201791789916324 );

    series.add(2, 0.9727097916233601 );

    series.add(3, 0.9949972829175494);

    */



    XYDataset xyDataset = new XYSeriesCollection(series);





    JFreeChart chart = ChartFactory.createXYLineChart

    ("Temp = 85", "k", "Pk",xyDataset, PlotOrientation.VERTICAL, true, true, false);

    ChartFrame frame1=new ChartFrame("XYLine Chart",chart);

    frame1.setVisible(true);

    frame1.setSize(600,400);







    }//End of method





    //***************





    }//end of class

    in data.txt has following values
    0.0 0.8201791789916324 0.9727097916233601 0.9949972829175494 0.9930928370666989 0.9757838836701933 0.9610936247552858 0.9085823680551047 0.6555671891250983

    this works fine for the above values but how to plot for below values
    2012-02-13 15:14:43:038 234,567,123


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to plot line graph using jfreechart reading from text file

    How do you want to convert a date and time to a number that can be plotted?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to plot line graph using jfreechart reading from text file

    we want it in the same format that i have mentioned above ie yyyy-mm-dd hh:mm:ss:SSS

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to plot line graph using jfreechart reading from text file

    Can you explain how you want to plot date values?
    Given some dates like this: yyyy-mm-dd hh:mm:ss:SSS

    What do would you plot?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How to plot line graph using jfreechart reading from text file

    I'm not fully clear as to what the requirement is, but if I understand correctly you might want to take a look at the DateAxis class
    DateAxis (JFreeChart Class Library (version 1.0.14))

  6. #6
    Junior Member
    Join Date
    Mar 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to plot line graph using jfreechart reading from text file

    i want to plot the graph with date as x axis lyk in form of 2012-03-02 15:23:43:056 in y-axis a number..

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to plot line graph using jfreechart reading from text file

    Does the API doc for the package you are using describe how to use dates on the x axis?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How to plot line graph using jfreechart reading from text file


  9. #9
    Junior Member
    Join Date
    Mar 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to plot line graph using jfreechart reading from text file

    we used dateaxis but it doesn't work.if thr is some sample code please let me know..its very urgent..

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to plot line graph using jfreechart reading from text file

    What does the doc say for how to use the code?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Not Reading From Text File
    By JavaLaxer15 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 18th, 2012, 11:16 AM
  2. Trouble Reading Line in File
    By Mandraix in forum What's Wrong With My Code?
    Replies: 9
    Last Post: April 4th, 2011, 10:47 PM
  3. Writing to a specific line in a text file
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 7th, 2011, 09:11 PM
  4. reading string in from text file
    By basketball8533 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: December 3rd, 2010, 05:31 PM
  5. Reading a lines from text file
    By kiran in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: September 26th, 2010, 10:54 PM