Results 1 to 4 of 4
- 03-31-2012, 09:21 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
how to plot line graph using jfreechart reading x and y axis 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
x-axis y-axis
2012-02-13 15:14:43:038 234,567,123
- 03-31-2012, 04:44 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
Re: how to plot line graph using jfreechart reading x and y axis from text file?
- 04-02-2012, 12:05 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
Re: how to plot line graph using jfreechart reading x and y axis from text file?
Help!!! Its urgent..
- 04-02-2012, 01:56 PM #4
Re: how to plot line graph using jfreechart reading x and y axis from text file?
No it's not
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
How to plot the graph,where the data from text file?
By Haryanti in forum New To JavaReplies: 2Last Post: 12-01-2011, 06:11 PM -
java graph plot taking file data
By niloR19 in forum AWT / SwingReplies: 3Last Post: 11-28-2011, 06:56 PM -
Reading first and last word of each line in a text file
By yap_1991 in forum New To JavaReplies: 3Last Post: 06-26-2010, 08:11 AM -
Reading part of a line in a text file
By aaronfsimons in forum New To JavaReplies: 3Last Post: 05-04-2009, 07:57 AM -
How to Customize Jfreechart value axis?
By neeraj.singh in forum AWT / SwingReplies: 0Last Post: 02-16-2009, 08:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks