PieChart.razor.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. [Obsolete]
  49. protected async override Task OnInitializedAsync()
  50. {
  51. Datas = await reportService.GetAppealReportData(1, DateTime.Parse("2022-02-01"), null, null);
  52. if (Datas != null)
  53. {
  54. Option1 = GetPieOption(Datas);
  55. pieChart.Refresh();
  56. StateHasChanged();
  57. }
  58. await base.OnInitializedAsync();
  59. }
  60. private EChartsOption<P.Pie> GetPieOption(share.ChartDatas datas)
  61. {
  62. List<object> seriesData = new List<object>();
  63. foreach(var data in datas.Datas)
  64. {
  65. seriesData.Add(new { Name = data.type, Value = data.value });
  66. }
  67. return Option1 = new()
  68. {
  69. Title= new Blazor.ECharts.Options.Title()
  70. {
  71. Text = datas.Title ,
  72. Left = "center"
  73. },
  74. Tooltip = new()
  75. {
  76. Trigger = TooltipTrigger.Item,
  77. Formatter = "{a} <br/>{b}: {c} ({d}%)"
  78. },
  79. Legend = new()
  80. {
  81. Show = false,
  82. Orient = Orient.Vertical,
  83. Left = 10,
  84. Data = datas.GetSeries()
  85. },
  86. Series = new()
  87. {
  88. new P.Pie()
  89. {
  90. Name = datas.Title,
  91. Radius = new[] { "50%", "70%" },
  92. AvoidLabelOverlap = false,
  93. //Label = new()
  94. //{
  95. // Show = true,
  96. // Position = LabelPosition.Inside,
  97. //},
  98. //LabelLine = new() { Show = true },
  99. Data = seriesData
  100. }
  101. }
  102. };
  103. }
  104. private void OnTimeRangeChange(DateRangeChangedEventArgs args)
  105. {
  106. msgService.Info($"Selected Time: {JsonSerializer.Serialize(args.Dates)}");
  107. Console.WriteLine($"Selected Time: {JsonSerializer.Serialize(args.Dates)}");
  108. Console.WriteLine($"Formatted Selected Time: {JsonSerializer.Serialize(args.DateStrings)}");
  109. if (args.Dates?.Length > 0){
  110. start = args.Dates[0];
  111. }
  112. if (args.Dates?.Length > 1)
  113. {
  114. end = args.Dates[1];
  115. }
  116. }
  117. private bool _noIconLoading;
  118. private async Task OnButtonClick()
  119. {
  120. _noIconLoading = true;
  121. Datas = await reportService.GetAppealReportData(iType, start, end, null);
  122. if (Datas != null)
  123. {
  124. Option1 = GetPieOption(Datas);
  125. pieChart.Refresh();
  126. StateHasChanged();
  127. }
  128. _noIconLoading = false;
  129. }
  130. }
  131. }