StaffStaticsReport.razor.cs 6.7 KB

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