Pure Programmer
Blue Matrix


Cluster Map

Project: Histogram

Write a program to compute a [[histogram]] graph. The program should accept frequency data from stdin. The input data should be tab-delimited, two columns. The first column is the label and the second column is the frequency (count / total). All the fequencies should total 100%. The first line will be the column headers, the remaining lines will be data. Print the label in a fields of 18 characters, right justified, the frequency as a percentage (frequency * 100) in a fixed width field of 8 and then a string of equal signs to form the histogram bar. The histogram bars should be between 0 and 50 equal signs where 50 represents the maximum frequency found. You can use the FrequencyTableBytes or FrequencyTableChars project to generate frequency tables then select just the appropriate columns using the ReorderColumns project.

$ ./FrequencyTableChars < some_text_file | ./ReorderColumns 2 4 | ./Histogram

Output
$ node Histogram.js < ../../data/text/FreqData1.txt ( ) 2.0248% ===== ( ) 21.2873% ================================================== (") 0.0041% (() 0.0104% ()) 0.0104% (,) 1.1697% === (-) 0.1056% (.) 0.6004% = (0) 0.0083% (1) 0.0745% ... (q) 0.0973% (r) 4.4264% ========== (s) 4.9543% ============ (t) 7.5506% ================== (u) 1.5466% ==== (v) 0.8613% == (w) 0.7184% == (x) 0.1967% (y) 1.0186% == (z) 0.0642%

Solution