123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- using AntDesign;
- using Blazor.ECharts.Options;
- using Blazor.ECharts.Options.Enum;
- using Microsoft.AspNetCore.Components;
- using System;
- using System.Collections.Generic;
- using System.Text.Json;
- using System.Threading.Tasks;
- using wispro.sp.web.Services;
- using P = Blazor.ECharts.Options.Series.Pie;
- namespace wispro.sp.web.Pages.Report
- {
- public partial class PieChart
- {
- private int iType = 1;
- private DateTime? start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
- private DateTime? end = DateTime.Now;
- Blazor.ECharts.Components.EPie pieChart;
- internal class TJType
- {
- public string Name { get; set; }
- public int value { get; set; }
- }
- List<TJType> Types = new List<TJType>
- {
- new TJType { value = 0,Name = "申诉人统计" },
- new TJType { value = 1,Name = "申诉类型统计" },
- new TJType { value = 2, Name = "部门申诉统计" },
- //new TJType { value = 3, Name = "申诉人每月申诉统计" },
- };
- private EChartsOption<P.Pie> Option1;
- share.ChartDatas Datas=new share.ChartDatas() {
- Title ="初始化标题",
- Datas = new List<share.ChartData>() {
- new share.ChartData(){ type ="A", value =1, year="", CustomerType ="", CustomerYear=""},
- new share.ChartData(){ type ="B",value =5, year="",CustomerType ="", CustomerYear=""}
- },
- ATitle ="ATitle",
- BTitle="",
- };
- List<object> ShowData = new List<object>()
- {
- new {type="A",value=1},
- new {type="B",value=5}
- };
-
- [Inject] ReportService reportService { get; set; }
- [Inject] MessageService msgService { get; set; }
- [Inject] protected IAuthService _authService { get; set; }
- [Obsolete]
- protected async override Task OnInitializedAsync()
- {
- await base.OnInitializedAsync();
- await _authService.CanVisitResource();
- await OnButtonClick();
- //Datas = await reportService.GetAppealReportData(1, DateTime.Parse("2022-02-01"), null, null);
- //if (Datas != null)
- //{
- // Option1 = GetPieOption(Datas);
- // pieChart.Refresh();
- // StateHasChanged();
- //}
-
- }
- private EChartsOption<P.Pie> GetPieOption(share.ChartDatas datas)
- {
- List<object> seriesData = new List<object>();
- foreach(var data in datas.Datas)
- {
- seriesData.Add(new { Name = data.type, Value = data.value });
- }
- return Option1 = new()
- {
- Toolbox = new() {
- Show= true,
- Feature=new()
- {
- SaveAsImage = new()
- {
- PixelRatio =2,
- Name="保存图片"
- }
- }
- },
- Title= new Blazor.ECharts.Options.Title()
- {
- Text = datas.Title ,
- Left = "center"
- },
- Tooltip = new()
- {
- Trigger = TooltipTrigger.Item,
- Formatter = "{a} <br/>{b}: {c} ({d}%)"
- },
- Legend = new()
- {
- Show = false,
- Orient = Orient.Vertical,
- Left = 10,
- Data = datas.GetSeries()
- },
- Series = new()
- {
- new P.Pie()
- {
- Name = datas.Title,
- Radius = new[] { "50%", "70%" },
- AvoidLabelOverlap = false,
- Label = new()
- {
- Show = true,
- Formatter= "{b}\r\n{c} ({d}%)"
- },
- //LabelLine = new() { Show = true },
- Data = seriesData
- }
- }
- };
- }
- private void OnTimeRangeChange(DateRangeChangedEventArgs args)
- {
- msgService.Info($"Selected Time: {JsonSerializer.Serialize(args.Dates)}");
-
- if (args.Dates?.Length > 0){
- start = args.Dates[0];
- }
- if (args.Dates?.Length > 1)
- {
- end = args.Dates[1];
- }
-
- }
- private bool _noIconLoading;
- private async Task OnButtonClick()
- {
- _noIconLoading = true;
- Datas = await reportService.GetAppealReportData(iType, start, end, null);
- if (Datas != null)
- {
- Option1 = GetPieOption(Datas);
- pieChart.Refresh();
- StateHasChanged();
- }
- _noIconLoading = false;
- }
- }
- }
|