AppealTrend.razor.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using AntDesign;
  2. using Blazor.ECharts.Options;
  3. using Microsoft.AspNetCore.Components;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Text.Json;
  9. using System.Threading.Tasks;
  10. using wispro.sp.share;
  11. using wispro.sp.web.Services;
  12. using Blazor.ECharts.Options;
  13. using Blazor.ECharts.Options.Enum;
  14. using L = Blazor.ECharts.Options.Series.Line;
  15. namespace wispro.sp.web.Pages.Report
  16. {
  17. public partial class AppealTrend
  18. {
  19. private int iType = 3;
  20. private DateTime? start = new DateTime(DateTime.Now.Year, 1, 1);
  21. private DateTime? end = DateTime.Now;
  22. private EChartsOption<L.Line> option;
  23. private Blazor.ECharts.Components.ELine chart;
  24. internal class TJType
  25. {
  26. public string Name { get; set; }
  27. public int value { get; set; }
  28. }
  29. List<TJType> Types = new List<TJType>
  30. {
  31. new TJType { value = 3,Name = "申诉人统计" },
  32. new TJType { value = 4,Name = "申诉类型统计" },
  33. new TJType { value = 5,Name = "部门申诉统计" },
  34. };
  35. share.ChartDatas Datas = new share.ChartDatas()
  36. {
  37. Title = "初始化标题",
  38. Datas = new List<share.ChartData>() {
  39. new share.ChartData(){ type ="部门一", value =1, year="2022-01", CustomerType ="", CustomerYear=""},
  40. new share.ChartData(){ type ="部门一",value =5, year="2022-02",CustomerType ="", CustomerYear=""},
  41. new share.ChartData(){ type ="部门二", value =3, year="2022-01", CustomerType ="", CustomerYear=""},
  42. new share.ChartData(){ type ="部门二",value =4, year="2022-02",CustomerType ="", CustomerYear=""},
  43. new share.ChartData(){ type ="部门三",value =2.5, year="2022-02",CustomerType ="", CustomerYear=""}
  44. },
  45. ATitle = "部门",
  46. BTitle = "申诉月份"
  47. };
  48. [Inject] ReportService reportService { get; set; }
  49. [Inject] MessageService msgService { get; set; }
  50. private void OnTimeRangeChange(DateRangeChangedEventArgs args)
  51. {
  52. msgService.Info($"Selected Time: {JsonSerializer.Serialize(args.Dates)}");
  53. if (args.Dates?.Length > 0)
  54. {
  55. Console.WriteLine(args.Dates[0]);
  56. start = args.Dates[0];
  57. }
  58. if (args.Dates?.Length > 1)
  59. {
  60. end = args.Dates[1];
  61. }
  62. }
  63. private bool _noIconLoading;
  64. private async Task OnButtonClick()
  65. {
  66. _noIconLoading = true;
  67. Datas = await reportService.GetAppealReportData(iType, start, end, null);
  68. GetOption();
  69. _noIconLoading = false;
  70. }
  71. private void GetOption()
  72. {
  73. if (Datas != null)
  74. {
  75. List<object> series = new List<object>();
  76. DataTable dt = Datas.GetTableData();
  77. foreach (DataRow row in dt.Rows)
  78. {
  79. L.Line l = new L.Line();
  80. l.Name = row[0].ToString();
  81. List<double> data = new List<double>();
  82. for (int i = 1; i < dt.Columns.Count; i++)
  83. {
  84. double dTem = 0;
  85. if(!double.TryParse(row[i].ToString(), out dTem))
  86. {
  87. dTem = 0;
  88. }
  89. data.Add(dTem);
  90. }
  91. l.Data = data;
  92. series.Add(l);
  93. }
  94. Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(series, new JsonSerializerOptions()
  95. {
  96. DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
  97. }));
  98. option = new()
  99. {
  100. Toolbox = new()
  101. {
  102. Show = true,
  103. Feature = new()
  104. {
  105. SaveAsImage = new()
  106. {
  107. PixelRatio = 2,
  108. Name = "保存图片"
  109. }
  110. }
  111. },
  112. Tooltip = new()
  113. {
  114. Trigger = TooltipTrigger.Item,
  115. Formatter = "{a} <br/>{b}: {c}"
  116. },
  117. Title = new()
  118. {
  119. Text = Datas.Title
  120. },
  121. YAxis = new()
  122. {
  123. new()
  124. {
  125. Type = AxisType.Value,
  126. Name = "申诉量",
  127. AxisLine = new()
  128. {
  129. Show = true,
  130. }
  131. }
  132. },
  133. XAxis = new()
  134. {
  135. new()
  136. {
  137. Type = AxisType.Category,
  138. Data = Datas.GetYear(),
  139. Name = Datas.BTitle
  140. }
  141. },
  142. Series = series
  143. };
  144. Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(option, new JsonSerializerOptions()
  145. {
  146. DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
  147. }));
  148. }
  149. }
  150. protected async override Task OnInitializedAsync()
  151. {
  152. Datas = await reportService.GetAppealReportData(iType, DateTime.Parse("2022-01-01"), DateTime.Now, null);
  153. GetOption();
  154. StateHasChanged();
  155. await base.OnInitializedAsync();
  156. }
  157. }
  158. }