PieChart.razor.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using AntDesign;
  2. using AntDesign.Charts;
  3. using Microsoft.AspNetCore.Components;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text.Json;
  8. using System.Threading.Tasks;
  9. using wispro.sp.web.Services;
  10. namespace wispro.sp.web.Pages.Report
  11. {
  12. public partial class PieChart
  13. {
  14. private int iType = 1;
  15. private DateTime? start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
  16. private DateTime? end = DateTime.Now;
  17. internal class TJType
  18. {
  19. public string Name { get; set; }
  20. public int value { get; set; }
  21. }
  22. List<TJType> Types = new List<TJType>
  23. {
  24. new TJType { value = 0,Name = "申诉人统计" },
  25. new TJType { value = 1,Name = "申诉类型统计" },
  26. new TJType { value = 2, Name = "部门申诉统计" },
  27. //new TJType { value = 3, Name = "申诉人每月申诉统计" },
  28. };
  29. private AntDesign.Charts.IChartComponent chart;
  30. private PieConfig config4 = new PieConfig
  31. {
  32. ForceFit = true,
  33. Title = new AntDesign.Charts.Title
  34. {
  35. Visible = true,
  36. Text = "初始化标题",
  37. AlignTo = "middle",
  38. Style= new TextStyle()
  39. {
  40. FontSize=20,
  41. Stroke="#2a3b4c",
  42. Fill = "#AABBDD",
  43. Opacity= 10
  44. }
  45. },
  46. Description = new Description
  47. {
  48. Visible = false,
  49. Text = "When the type of the pie chart label is set to spider, the labels are divided into two groups, and they are displayed in alignment by pulling lines on both sides of the chart. Generally speaking, the labels of the spider layout are less likely to block each other."
  50. },
  51. Radius = 0.8,
  52. InnerRadius =0.5,
  53. AngleField = "value",
  54. ColorField = "type",
  55. Label = new PieLabelConfig
  56. {
  57. Visible = true,
  58. Type = "spider",//"inner",//"outer"//,
  59. //Formatter= "() => $'{(percent * 100).toFixed(0)}%'",
  60. },
  61. Legend= new Legend
  62. {
  63. Visible=false,
  64. Position= "bottom",
  65. }
  66. };
  67. share.ChartDatas Datas=new share.ChartDatas() {
  68. Title ="初始化标题",
  69. Datas = new List<share.ChartData>() {
  70. new share.ChartData(){ type ="A", value =1, year="", CustomerType ="", CustomerYear=""},
  71. new share.ChartData(){ type ="B",value =5, year="",CustomerType ="", CustomerYear=""}
  72. },
  73. ATitle ="ATitle",
  74. BTitle="",
  75. };
  76. List<object> ShowData = new List<object>()
  77. {
  78. new {type="A",value=1},
  79. new {type="B",value=5}
  80. };
  81. [Inject] ReportService reportService { get; set; }
  82. [Inject] MessageService msgService { get; set; }
  83. [Obsolete]
  84. protected async override Task OnInitializedAsync()
  85. {
  86. Datas = await reportService.GetAppealReportData(1, DateTime.Parse("2022-02-01"), null, null);
  87. if (Datas != null)
  88. {
  89. config4.Title.Text = Datas.Title;
  90. config4.XField = Datas.ATitle;
  91. await chart.ChangeData(Datas.Datas);
  92. await chart.UpdateChart(config4);
  93. StateHasChanged();
  94. }
  95. await base.OnInitializedAsync();
  96. }
  97. private void OnTimeRangeChange(DateRangeChangedEventArgs args)
  98. {
  99. msgService.Info($"Selected Time: {JsonSerializer.Serialize(args.Dates)}");
  100. Console.WriteLine($"Selected Time: {JsonSerializer.Serialize(args.Dates)}");
  101. Console.WriteLine($"Formatted Selected Time: {JsonSerializer.Serialize(args.DateStrings)}");
  102. if (args.Dates?.Length > 0){
  103. start = args.Dates[0];
  104. }
  105. if (args.Dates?.Length > 1)
  106. {
  107. end = args.Dates[1];
  108. }
  109. }
  110. private bool _noIconLoading;
  111. private async Task OnButtonClick()
  112. {
  113. _noIconLoading = true;
  114. Datas = await reportService.GetAppealReportData(iType, start, end, null);
  115. if (Datas != null)
  116. {
  117. config4.Title.Text = Datas.Title;
  118. config4.XField = Datas.ATitle;
  119. await chart.ChangeData(Datas.Datas);
  120. await chart.UpdateChart(config4);
  121. StateHasChanged();
  122. }
  123. _noIconLoading = false;
  124. }
  125. }
  126. }