private void FillChartInhabitants(string title, Func <ModelData.RegionData, float> dataToExtract) { var dateFrom = FromDate?.Invoke() ?? DateTime.Today; var dateTo = ToDate?.Invoke() ?? DateTime.Today; var top = Top?.Invoke()?.value ?? 5; var data = DataExtractorRegion.FillRangeDataInhabitants(dateFrom, dateTo, top, dataToExtract); Title = dateFrom.Date == dateTo.Date ? $"{title} {dateFrom.Date.ToShortDateString()}" : $"{title} {Properties.Resources.BetweenDate} {dateFrom.Date:dd/MM/yy} {Properties.Resources.And} {dateTo.Date:dd/MM/yy}"; Func <ChartPoint, string> labelPoint = chartPoint => string.Format("{0}", chartPoint.Y.ToString("#,##0.##")); var series = new SeriesCollection(); foreach (var region in data) { series.Add( new PieSeries() { Title = region.lbl, Values = new ChartValues <float> { region.value }, DataLabels = true, LabelPoint = labelPoint }); } this.chart.Series = series; this.chart.LegendLocation = LegendLocation.Right; }
private void FillChartCasesSwab() { var dateFrom = FromDate?.Invoke() ?? DateTime.Today; var dateTo = ToDate?.Invoke() ?? DateTime.Today; var top = Top?.Invoke()?.value ?? 5; var title = Properties.Resources.RelationshipCasesSwabs; var swab = DataExtractorRegion.FillRangeData(dateFrom, dateTo, 100, p => p.nuovi_tamponi).OrderBy(p => p.lbl); var cases = DataExtractorRegion.FillRangeData(dateFrom, dateTo, 100, p => p.nuovi_positivi).OrderBy(p => p.lbl); var data = cases.Zip(swab, (c, s) => new ReturnData() { lbl = c.lbl, data = c.data, value = c.value / s.value }) .OrderByDescending(o => o.value) .Take(top) .ToList(); var Title = dateFrom.Date == dateTo.Date ? $"{title} {dateFrom.Date.ToShortDateString()}" : $"{title} {Properties.Resources.BetweenDate} {dateFrom.Date.ToString("dd/MM/yy")} {{Properties.Resources.And}} {dateTo.Date.ToString("dd/MM/yy")}"; Func <ChartPoint, string> labelPoint = chartPoint => string.Format("{0}", chartPoint.Y.ToString("P2")); var series = new SeriesCollection(); foreach (var region in data) { series.Add( new PieSeries() { Title = region.lbl, Values = new ChartValues <float> { region.value }, DataLabels = true, LabelPoint = labelPoint }); } this.chart.Series = series; this.chart.LegendLocation = LegendLocation.Right; }