StatBean Name: Histogram

Purpose: Constructs a frequency histogram to show the distribution of numeric data.

DataSource: Tabulation.


Read/Write Properties
NameTypeDescriptionPossible ValuesDefault Value
drawNormalCurvebooleanWhether to add the best-fitting normal distribution.true,falsefalse
drawVerticalbooleanWhether to make the bars vertical.true,falsetrue
fillColorColorColor to use for the bars.Any valid Color.Color.blue.
resolutionintFor continuous distributions, the number of points at which the function is calculated.50+500
scaleByPercentagebooleanWhether to scale the axes by percentage rather than frequency.true,falsefalse

Code Sample

//create a datasource bean
FileDataSource fileDataSource1 = new STATBEANS.FileDataSource();

//set the file name to be read
fileDataSource1.setFileName("c:\\statbeans\\samples\\cardata.txt");

//create a calculation bean
Tabulation tabulation1 = new STATBEANS.Tabulation();

//set the column to be tabulated
tabulation1.setXVariableName("mpg");

//set the type of tabulation and the limits
tabulation1.setDataType("Continuous");
tabulation1.setFrom(0.0);
tabulation1.setTo(60.0);
tabulation1.setBy(5.0);

//create a chart bean
Histogram histogram1 = new STATBEANS.Histogram();

//set the fill color
histogram1.setFillColor(Color.green);

//add a normal curve
histogram1.setAddNormalCurve(true);

//make the calculation bean a listener for changes in the FileDataSource bean
fileDataSource1.addDataChangeListener(tabulation1.listenerForDataChange);

//make the plot bean a listener for changes in the tabulation bean
tabulation1.addDataChangeListener(histogram1.listenerForDataChange);

//instruct the fileDataSource bean to read the file
fileDataSource1.readData();