PieChart.razor.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using AntDesign;
  2. using Blazor.ECharts.Options;
  3. using Blazor.ECharts.Options.Enum;
  4. using Microsoft.AspNetCore.Components;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Text.Json;
  8. using System.Threading.Tasks;
  9. using wispro.sp.web.Services;
  10. using P = Blazor.ECharts.Options.Series.Pie;
  11. namespace wispro.sp.web.Pages.Report
  12. {
  13. public partial class PieChart
  14. {
  15. private int iType = 1;
  16. private DateTime? start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
  17. private DateTime? end = DateTime.Now;
  18. Blazor.ECharts.Components.EPie pieChart;
  19. internal class TJType
  20. {
  21. public string Name { get; set; }
  22. public int value { get; set; }
  23. }
  24. List<TJType> Types = new List<TJType>
  25. {
  26. new TJType { value = 0,Name = "申诉人统计" },
  27. new TJType { value = 1,Name = "申诉类型统计" },
  28. new TJType { value = 2, Name = "部门申诉统计" },
  29. //new TJType { value = 3, Name = "申诉人每月申诉统计" },
  30. };
  31. private EChartsOption<P.Pie> Option1;
  32. share.ChartDatas Datas=new share.ChartDatas() {
  33. Title ="初始化标题",
  34. Datas = new List<share.ChartData>() {
  35. new share.ChartData(){ type ="A", value =1, year="", CustomerType ="", CustomerYear=""},
  36. new share.ChartData(){ type ="B",value =5, year="",CustomerType ="", CustomerYear=""}
  37. },
  38. ATitle ="ATitle",
  39. BTitle="",
  40. };
  41. List<object> ShowData = new List<object>()
  42. {
  43. new {type="A",value=1},
  44. new {type="B",value=5}
  45. };
  46. [Inject] ReportService reportService { get; set; }
  47. [Inject] MessageService msgService { get; set; }
  48. [Inject] protected IAuthService _authService { get; set; }
  49. [Obsolete]
  50. protected async override Task OnInitializedAsync()
  51. {
  52. await _authService.CanVisitResource();
  53. Datas = await reportService.GetAppealReportData(1, DateTime.Parse("2022-02-01"), null, null);
  54. if (Datas != null)
  55. {
  56. Option1 = GetPieOption(Datas);
  57. pieChart.Refresh();
  58. StateHasChanged();
  59. }
  60. await base.OnInitializedAsync();
  61. }
  62. private EChartsOption<P.Pie> GetPieOption(share.ChartDatas datas)
  63. {
  64. List<object> seriesData = new List<object>();
  65. foreach(var data in datas.Datas)
  66. {
  67. seriesData.Add(new { Name = data.type, Value = data.value });
  68. }
  69. return Option1 = new()
  70. {
  71. Toolbox = new() {
  72. Show= true,
  73. Feature=new()
  74. {
  75. SaveAsImage = new()
  76. {
  77. PixelRatio =2,
  78. Name="保存图片"
  79. }
  80. }
  81. },
  82. Title= new Blazor.ECharts.Options.Title()
  83. {
  84. Text = datas.Title ,
  85. Left = "center"
  86. },
  87. Tooltip = new()
  88. {
  89. Trigger = TooltipTrigger.Item,
  90. Formatter = "{a} <br/>{b}: {c} ({d}%)"
  91. },
  92. Legend = new()
  93. {
  94. Show = false,
  95. Orient = Orient.Vertical,
  96. Left = 10,
  97. Data = datas.GetSeries()
  98. },
  99. Series = new()
  100. {
  101. new P.Pie()
  102. {
  103. Name = datas.Title,
  104. Radius = new[] { "50%", "70%" },
  105. AvoidLabelOverlap = false,
  106. Label = new()
  107. {
  108. Show = true,
  109. Formatter= "{b}\r\n{c} ({d}%)"
  110. },
  111. //LabelLine = new() { Show = true },
  112. Data = seriesData
  113. }
  114. }
  115. };
  116. }
  117. private void OnTimeRangeChange(DateRangeChangedEventArgs args)
  118. {
  119. msgService.Info($"Selected Time: {JsonSerializer.Serialize(args.Dates)}");
  120. if (args.Dates?.Length > 0){
  121. start = args.Dates[0];
  122. }
  123. if (args.Dates?.Length > 1)
  124. {
  125. end = args.Dates[1];
  126. }
  127. }
  128. private bool _noIconLoading;
  129. private async Task OnButtonClick()
  130. {
  131. _noIconLoading = true;
  132. Datas = await reportService.GetAppealReportData(iType, start, end, null);
  133. if (Datas != null)
  134. {
  135. Option1 = GetPieOption(Datas);
  136. pieChart.Refresh();
  137. StateHasChanged();
  138. }
  139. _noIconLoading = false;
  140. }
  141. }
  142. }