//Creating a fun little graph public static void CreateGraph(YearMap yearMap) { //Order the list of keys to get all of the years and find out how many years there were that someone lived in var orderedList = yearMap.YearVals.Keys.OrderBy(x => x).ToArray(); var numberOfYears = orderedList.Count(); var xvals = new int[numberOfYears]; var yvals = new int[numberOfYears]; for (int i = 0; i < yvals.Length; i++) { yvals[i] = yearMap.YearVals[orderedList[i]]; xvals[i] = orderedList[i]; } var chart = new Chart(); chart.Size = new Size(1000, 1000); Title title = new Title("Number of people alive each year"); title.Font = new Font("Calibri", 16, System.Drawing.FontStyle.Bold); chart.Titles.Add(title); var chartArea = new ChartArea(); chartArea.AxisX.LabelStyle.Font = new Font("Calibri", 8); chartArea.AxisY.LabelStyle.Font = new Font("Calibri", 8); chartArea.AxisY.Minimum = 0; chartArea.AxisX.Minimum = 1900; chartArea.AxisX.Maximum = 2000; chartArea.AxisX.Title = "Years"; chartArea.AxisX.TitleFont = new Font("Calibri", 14, System.Drawing.FontStyle.Bold); chartArea.AxisY.Title = "Number of People Alive"; chartArea.AxisY.TitleFont = new Font("Calibri", 14, System.Drawing.FontStyle.Bold); chartArea.AxisY.Interval = 1; chartArea.AxisX.Interval = 5; chart.ChartAreas.Add(chartArea); var series = new Series(); series.Name = "Series"; series.ChartType = SeriesChartType.Bar; chart.Series.Add(series); chart.Series["Series"].Points.DataBindXY(xvals, yvals); chart.Invalidate(); chart.SaveImage("../../Output/chart.png", ChartImageFormat.Png); }
//Create map of years and find the most lived years. public static YearMap FindMostLivedYear(List<Person> people) { YearMap years = new YearMap(); //Loop through the users and add the years they lived to the map. foreach(Person person in people) { for(int i = person.BirthYear; i <= person.DeathYear; i++) { years.AddYear(i); } } //Creating the list in the map of the most lived years years.GetMostLivedYears(); return years; }