I'm looking for an alternative towards a process that takes too much code and generates significant overhead...
This code fills in a Chartview (LineChart) and in order to display the progression of 6 different "Areas" it runs a query 6 times and add the series 6 times...
- public static void FillLineChart(ChartView chartView, CheckedDropDownList checkedDropDown, string dateFrom, string dateTo)
- {
- foreach (var i in checkedDropDown.CheckedItems)
- {
- var iindex = i.RowIndex + 1;
- if (iindex == 1)
- {
- LineSeries crime = new LineSeries();
- FunctionsDAL cr = new FunctionsDAL();
- foreach (var caseType in cr.ListCases(1, dateFrom, dateTo))
- {
- crime.DataPoints.Add(new CategoricalDataPoint(caseType.IncrementalTotal,
- CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(caseType.MonthNum)));
- }
- chartView.Series.Add(crime);
- crime.LegendTitle = "Crime";
- crime.Spline = true;
- }
- else if (iindex == 2)
- {
- }
- else if (iindex == 3)
- {
- }
- // The same 3 more times
- }
- }
How could I shorten up this process? or is this the way is supposed to be working?
Regards.

Nitin SontakkeRank #264 · 9.6K reputationPosted Jul 7, 2016, 8:27 PM EDT
Guest User40 reputationPosted Jul 8, 2016, 5:23 AM EDT
theLizardRank #1,079 · 1.8K reputationPosted Jul 8, 2016, 11:56 AM EDT
for (int i = 0; i < c.CheckedItems.Count; i++)
{
LineSeriescrime = newLineSeries();
FunctionsDALcr = newFunctionsDAL();
foreach (varcaseTypeincr.ListCases(1,dateFrom,dateTo))
{
crime.DataPoints.Add(newCategoricalDataPoint(caseType.IncrementalTotal,
CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(caseType.MonthNum)));
}
chartView.Series.Add(crime);
crime.LegendTitle = titil[i];
crime.Spline = true;
}
Guest User40 reputationPosted Jul 21, 2016, 6:45 AM EDT