/// <summary> /// 销量走势图 /// </summary> /// <param name="app"></param> /// <param name="title"></param> /// <returns></returns> private async Task <ChartViewConfig> SaleTrendChatPage_Chart(Module app, string title) { ChartViewConfig chartData = null; try { var result = await _reportingService.GetSaleTrendingAsync("day", this.ForceRefresh, new System.Threading.CancellationToken()); if (result != null && result.Any()) { var series = result.ToList(); if (series.Count > 50) { series = result.Take(50).ToList(); } chartData = new ChartViewConfig() { BackgroundColor = Color.White, ChartConfig = new ChartConfig { type = Wesley.ChartJS.ChartTypes.Line, data = ChartDataProvider.GetSaleTrendChat(series), } }; } return(chartData); } catch (Exception ex) { Crashes.TrackError(ex); return(chartData); } }
private void RefreshData(List <SaleTrending> series) { int i = 0; Random random = new Random(); if (series == null || series.Count == 0) { for (i = 1; i <= DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month); i++) { series.Add(new SaleTrending() { DateType = "DAY", NetAmount = random.Next(200), SaleAmount = random.Next(200), SaleDateName = DateTime.Now.AddDays(i).ToString("yyyy-MM-dd"), SaleReturnAmount = random.Next(200), SaleDate = DateTime.Now.AddDays(i) }); } } string[] weekdays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; series.ForEach(d => { if ("DAY" == d.DateType.ToUpper()) { d.SaleDateName = d.SaleDate.ToString("yyyy/MM/dd"); } else if ("WEEK" == d.DateType.ToUpper()) { d.SaleDateName = weekdays[Convert.ToInt32(d.SaleDate.DayOfWeek)]; } else if ("MONTH" == d.DateType.ToUpper()) { d.SaleDateName = d.SaleDate.ToString("yyyy-MM"); } }); RankSeries = new ObservableCollection <SaleTrending>(series); TotalAmount = RankSeries.Select(s => s.NetAmount).Sum(); var ranks = series.ToList(); if (ranks.Count > 10) { ranks = ranks.Take(10).ToList(); } var data = new ChartViewConfig() { BackgroundColor = Color.White, ChartConfig = new ChartConfig { type = DCMS.ChartJS.ChartTypes.Line, data = ChartDataProvider.GetSaleTrendChat(ranks), } }; ChartConfig = data; }