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();
}
}

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.