Creating histograms
Histograms, though similar in appearance to bar charts, are used to display the frequency of data items in relation to other items within the dataset. Each of the following examples using GRAL will use the DataTable
class to initially hold the data to be displayed. In this example, we will read data from a sample file called AgeofMarriage.csv
. This comma-separated file holds a list of ages at which people were first married.
We will create a new class, called HistogramExample
, which extends the JFrame
class and contains the following code within its constructor. We first create a DataReader
object to specify that the data is in CSV format. We then use a try-catch block to handle IO exceptions and call the DataReader
class's read
method to place the data directly into a DataTable
object. The first parameter of the read
method is a FileInputStream
object, and the second specifies the type of data expected from within the file:
DataReader readType= DataReaderFactory...