private void DrawBarChart() { int index = cbbTime.SelectedIndex; ChartData.TimeSpan time = (ChartData.TimeSpan)index; //LineChart.DrawChart(ChartData.GetDays(time)); }
private void DrawLineChart() { int index = cbbTime.SelectedIndex; ChartData.TimeSpan time = (ChartData.TimeSpan)index; string url = LineChart.DrawChart(time); lineChart.Source = new BitmapImage(new Uri(url)); }
public static string DrawChart(ChartData.TimeSpan time) { InitChartValue(time); string ChartValue = "&chd=t:0"; string ChartXLabel = "&chxl=0:|."; switch (time) { case TimeSpan._7Days: case TimeSpan._15Days: foreach (KeyValuePair <DateTime, float> data in Revenue) { ChartValue += "," + data.Value.ToString("0.00"); ChartXLabel += "|" + data.Key.Day + "/" + data.Key.Month; } break; case TimeSpan._4Weeks: foreach (KeyValuePair <DateTime, float> data in Revenue) { ChartValue += "," + data.Value.ToString("0.00"); ChartXLabel += "|" + data.Key.Day + "/" + data.Key.Month + "-" + data.Key.AddDays(6).Day + "/" + data.Key.AddDays(6).Month; } break; case TimeSpan._6Months: foreach (KeyValuePair <DateTime, float> data in Revenue) { ChartValue += "," + data.Value.ToString("0.00"); ChartXLabel += "|" + data.Key.Month + "/" + data.Key.Year; } break; } return(BaseChartURL + ChartType + ChartAutoScale + ChartColorFill + ChartAxis + ChartAxisColor + ChartColor + ChartDot + ChartGrid + ChartSize + ChartDot + ChartValue + ChartXLabel); }
public static string DrawChart(ChartData.TimeSpan time) { InitChartValue(time); string ChartData = "&chd=t:"; string ChartLabel = "&chl="; string ChartLegend = "&chdl="; using (StoreManagementEntities context = new StoreManagementEntities()) { foreach (KeyValuePair <int, int> product in TopProduct) { ChartData += product.Value + ","; ChartLabel += product.Value + "|"; string name = context.Products.Find(product.Key).ProductName; name = name.Replace(" ", "+"); if (name.Length > 20) { name = name.Substring(0, 20) + "..."; } ChartLegend += name + "|"; } } ChartData = ChartData.Remove(ChartData.Length - 1); ChartLabel = ChartLabel.Remove(ChartLabel.Length - 1); ChartLegend = ChartLegend.Remove(ChartLegend.Length - 1); return(BaseChartURL + ChartType + ChartColorFill + ChartColor + ChartSize + ChartData + ChartLabel + ChartLegend); }
private static void InitChartValue(ChartData.TimeSpan time) { Revenue = new Dictionary <DateTime, float>(); List <BillEntity> ListBillData = ChartsLayout.ListBillData.GetRange(0, ChartsLayout.ListBillData.Count); switch (time) { case TimeSpan._7Days: int day = 7; ListBillData.RemoveAll(entity => (DateTime.Today - entity.BillDate).Days >= day); for (int i = day - 1; i >= 0; i--) { Revenue.Add(DateTime.Today.AddDays(-i), 0); } foreach (BillEntity bill in ListBillData) { Revenue[bill.BillDate] += bill.TotalPrice * 1.0f / 1000000; } break; case TimeSpan._15Days: day = 15; ListBillData.RemoveAll(entity => (DateTime.Today - entity.BillDate).Days >= day); for (int i = day - 1; i >= 0; i--) { Revenue.Add(DateTime.Today.AddDays(-i), 0); } foreach (BillEntity bill in ListBillData) { Revenue[bill.BillDate] += bill.TotalPrice * 1.0f / 1000000; } break; case TimeSpan._4Weeks: DateTime startOfWeek = DateTime.Today; while (startOfWeek.DayOfWeek != DayOfWeek.Monday) { startOfWeek = startOfWeek.AddDays(-1); } List <DateTime> temp = new List <DateTime>(); for (int i = 3; i >= 0; i--) { DateTime monday = startOfWeek.AddDays(-i * 7); Revenue.Add(monday, 0); temp.Add(monday); } ListBillData.RemoveAll(entity => entity.BillDate < temp[0]); foreach (BillEntity bill in ListBillData) { foreach (DateTime date in temp) { int dayDiff = (bill.BillDate - date).Days; if (dayDiff >= 0 && dayDiff <= 6) { Revenue[date] += bill.TotalPrice * 1.0f / 1000000; } } } break; case TimeSpan._6Months: DateTime startOfMonth = DateTime.Today; while (startOfMonth.Day != 1) { startOfMonth = startOfMonth.AddDays(-1); } List <DateTime> ListStartOfMonth = new List <DateTime>(); for (int i = 0; i < 6; i++) { while (startOfMonth.Day != 1) { startOfMonth = startOfMonth.AddDays(-1); } startOfMonth = startOfMonth.AddDays(-1); } for (int i = 0; i < 6; i++) { while (startOfMonth.Day != 1) { startOfMonth = startOfMonth.AddDays(1); } Revenue.Add(startOfMonth, 0); ListStartOfMonth.Add(startOfMonth); startOfMonth = startOfMonth.AddDays(1); } ListBillData.RemoveAll(entity => entity.BillDate < ListStartOfMonth[0]); foreach (BillEntity bill in ListBillData) { foreach (DateTime date in ListStartOfMonth) { if (bill.BillDate.Month == date.Month && bill.BillDate.Year == date.Year) { Revenue[date] += bill.TotalPrice * 1.0f / 1000000; } } } break; } }
private static void InitChartValue(ChartData.TimeSpan time) { Dictionary <int, int> AllProduct = new Dictionary <int, int>(); List <BillEntity> ListBillData = ChartsLayout.ListBillData.GetRange(0, ChartsLayout.ListBillData.Count); //remove bills switch (time) { case TimeSpan._7Days: int day = 7; ListBillData.RemoveAll(entity => (DateTime.Today - entity.BillDate).Days >= day); break; case TimeSpan._15Days: day = 15; ListBillData.RemoveAll(entity => (DateTime.Today - entity.BillDate).Days >= day); break; case TimeSpan._4Weeks: DateTime startOfWeek = DateTime.Today; while (startOfWeek.DayOfWeek != DayOfWeek.Monday) { startOfWeek = startOfWeek.AddDays(-1); } List <DateTime> temp = new List <DateTime>(); for (int i = 3; i >= 0; i--) { DateTime monday = startOfWeek.AddDays(-i * 7); temp.Add(monday); } ListBillData.RemoveAll(entity => entity.BillDate < temp[0]); break; case TimeSpan._6Months: DateTime startOfMonth = DateTime.Today; while (startOfMonth.Day != 1) { startOfMonth = startOfMonth.AddDays(-1); } List <DateTime> ListStartOfMonth = new List <DateTime>(); for (int i = 0; i < 6; i++) { while (startOfMonth.Day != 1) { startOfMonth = startOfMonth.AddDays(-1); } startOfMonth = startOfMonth.AddDays(-1); } for (int i = 0; i < 6; i++) { while (startOfMonth.Day != 1) { startOfMonth = startOfMonth.AddDays(1); } ListStartOfMonth.Add(startOfMonth); startOfMonth = startOfMonth.AddDays(1); } ListBillData.RemoveAll(entity => entity.BillDate < ListStartOfMonth[0]); break; } foreach (BillEntity bill in ListBillData) { foreach (KeyValuePair <int, int> product in bill.ListProduct) { if (AllProduct.ContainsKey(product.Key)) { AllProduct[product.Key] += product.Value; } else { AllProduct.Add(product.Key, product.Value); } } } TopProduct = new Dictionary <int, int>(); for (int i = 0; i < 5; i++) { int max = -1; int prodID = -1; foreach (KeyValuePair <int, int> product in AllProduct) { if (product.Value >= max) { max = product.Value; prodID = product.Key; } } if (prodID != -1) { TopProduct.Add(prodID, max); AllProduct.Remove(prodID); } } }