I am just wondering if I could get some advice on implementing an algorithm for creating a JFreeChart. Basically, I am extracting some data from a JTable which contains information about patients. There are age categories for all patients such as 20-26, 26-30, 31-35, 35-40, 50-55, 55-60 etc. There are about 30 of them and every patient belongs to their corresponding age category. There is a button on top of the JTable which opens a frame containing the age distribution graph. What I am thinking of doing:
- Create an integer variable for every category
- Loop through the age details for all patients in the JTable
- Compare variables with the JTable data and increment by 1 if there is a match (lots of if statements to go in the loop)
- Store the categories names and the amount of people registered under every category in a HashMap
- Pass the map to the ChartFrame
I suppose this might be a relatively good way of doing this but I was wondering if somebody could possibly suggest a way of avoiding having to create a variable for every category and then having to do all those comparisons using about 30 if statements.
EDIT: I do not have the patient's exact age - only the category they belong to.