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; }
public void FillChartWithDailySwabCases(int region, string regionName) { var swab = DataExtractorRegion.FillDailySwabCases(region); var cases = DataExtractorRegion.FillDailyCases(region); this.chart.Series.Clear(); this.chart.AxisX.Clear(); this.chart.AxisY.Clear(); this.chart.Series = new SeriesCollection { new LineSeries { Title = $"{Properties.Resources.DailyCases} {regionName}", Values = new ChartValues <float>(cases.Select(s => s.value)), PointGeometry = DefaultGeometries.None, DataLabels = true, //LabelPoint = point => point.Y.ToString("N0"), ScalesYAt = 0 }, new LineSeries { Title = Properties.Resources.RelationshipCasesSwabs, Values = new ChartValues <float>(swab.Select(s => s.value)), PointGeometry = DefaultGeometries.None, DataLabels = false, ScalesYAt = 1 } }; this.chart.AxisX.Add(new Axis { Labels = swab.Select(s => s.lbl).ToList(), LabelsRotation = 15, Separator = new Separator { Step = 7, IsEnabled = true //disable it to make it invisible. } }); this.chart.AxisY.Add(new Axis { Title = Properties.Resources.NewCases, LabelFormatter = value => value.ToString("N0") }); this.chart.AxisY.Add(new Axis { Title = Properties.Resources.RelationshipCasesSwabs, LabelFormatter = value => value.ToString("P"), Position = AxisPosition.RightTop }); this.chart.LegendLocation = LegendLocation.Top; this.chart.Zoom = ZoomingOptions.X; }
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; }