View Single Post
  #1 (permalink)  
Old 10-25-2007, 11:32 PM
adlb1300 adlb1300 is offline
Member
 
Join Date: Jul 2007
Posts: 46
adlb1300 is on a distinguished road
Help Creating A Graph From Inputted Data
I have a program that requests a series of numbers from the user. Once everything is inputted the frequency of each number within a range is supposed to be graphed in a JFrame. The graph basically would show on the y-axis the ranges, ie 10-19, 0-9, and the x-axis would show the number falling into each range using a rectangle coming out of the location of the range on the y-axis. I can get the input to work and I have verified that my code compiling all of the data into an array that adds up the frequency is working. My problem is I have no clue where to start with the graphing part of it. I have tried some things with Swing and AWT but with my newbie understanding of Java the results were not good. Here is the code I already have:

Code:
import java.io.*; import javax.swing.*; public class Histogram { /** * @param args the command line arguments */ public static void main(String[] args) { // creates int inputtedValue[] = new int[ 10 ]; // array to hold inputted data for( int inputCounter = 0; inputCounter < inputtedValue.length; inputCounter++ ) { String input = JOptionPane.showInputDialog ("Please enter a number between 0 and 99\n" + "Stop entering values at any time by entering -1.\n"); int numberProvided = Integer.parseInt(input); inputtedValue[ inputCounter ] = numberProvided; HistogramFreq freqCalc = new HistogramFreq(inputtedValue); freqCalc.determineFrequency(); } } // end main } // end class Histogram
Code:
import java.awt.*; import javax.swing.*; public class HistogramFreq { private int valuesProvided[]; public HistogramFreq(int inputtedValue[]) { valuesProvided = inputtedValue; } public void determineFrequency(){ // stores frequency of inputted numbers in the appropriate ranges int frequency[] = new int [10]; // for each range increment the appropriate range for( int valueEntered : valuesProvided) ++frequency[valueEntered/10]; } // end method determineFrequency() } // end class HistogramFreq
Thanks
Reply With Quote
Sponsored Links