954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How can i prepare a histogram

How can i plot a histogram from the results of the following code.

Thanks in advance for your help
Serkan

import java.io.*;

public class LineLen {
public static void main(String args[]) throws Throwable {

//
// Open the file
final String filename = "LineLen22.java";
BufferedReader infile = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
// Read in a line
// While the line is not null
// Read it in
// Set the length to be 'len'
// increment the line number
// print line number, len
// read in the next line
String line = infile.readLine();
int linenum = 0;
while (line != null) {
int len = line.length();
linenum++;
System.out.println(linenum + "\t" + len);
line = infile.readLine();
}
}

serkanozgen
Newbie Poster
2 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

Hi everyone,

I not sure if you can plot a histogram in console mode but as for gui mode you can but it is extremely hard and difficult and most people tend to use third party packages. Try to google for them and you will a lot of them. There are also a few open source packages which you can use for free in your software development.

Yours Sincerely

Richard West

freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
 

sure you can plot a histogram in console mode.
After all it's just a collation of data with one column or row for each value (a barchart).

Easiest on the commandline would be to use a line for each value and just print a single block or something for each number in your count.

Say you want to plot the array [2,3,4,6,3,4] which is the number of occurrances of something in your file (say specific words).
you'd print something like

++
+++
++++
++++++
+++
++++

That's easy enough to arrange for...

In a Swing application collecting the data works identically but you need something to create the graphical representation, which is where most people will indeed tend to use existing graphics packages but using a simple Graphics or Image object you could get there as well.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You