using Newtonsoft.Json; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using TMPro; using UnityEngine; using UnityEngine.UI; using System; public class DataVersionPanel : MonoBehaviour { public Date116 date116; [Header("人数增加或减少")] public Image image; public Text Usercount; public Sprite Up; public Sprite Down; public TextMeshProUGUI count; [Header("表格")] public WMG_Axis_Graph WmgAxisGraph; public WMG_Series WmgSeries; // Start is called before the first frame update async void Start() { date116 = await OnClick116BpanelAsync(); Debug.Log(date116.userRegisterDailyResponseVoList.Count); Init(); SETGraph(); } public void Init() { count.text = "" + (int)date116.userVoluteCoinCount; if (date116.userRegisterDailyResponseVoList[date116.userRegisterDailyResponseVoList.Count-1].registerUser >=date116.userRegisterDailyResponseVoList[date116.userRegisterDailyResponseVoList.Count - 2].registerUser) { image.sprite= Up; Usercount.text = $"{(int)date116.userRegisterDailyResponseVoList[date116.userRegisterDailyResponseVoList.Count-1].registerUser- (int)date116.userRegisterDailyResponseVoList[date116.userRegisterDailyResponseVoList.Count - 2].registerUser}"; } else { image.sprite = Down; Usercount.text = $"{(int)date116.userRegisterDailyResponseVoList[date116.userRegisterDailyResponseVoList.Count-2].registerUser - (int)date116.userRegisterDailyResponseVoList[date116.userRegisterDailyResponseVoList.Count-1].registerUser}"; } } long FindMinValue() { long minValue = date116.userRegisterDailyResponseVoList[0].registerUser; foreach (var num in date116.userRegisterDailyResponseVoList) { if (num.registerUser < minValue) { minValue = num.registerUser; } } return minValue; } long FindMaxValue() { long maxValue = date116.userRegisterDailyResponseVoList[0].registerUser; foreach (var num in date116.userRegisterDailyResponseVoList) { if (num.registerUser > maxValue) { maxValue = num.registerUser; } } return maxValue; } public void SETGraph() { WmgAxisGraph.xAxis.AxisNumTicks = date116.userRegisterDailyResponseVoList.Count;//x轴\ Debug.Log(WmgAxisGraph.xAxis.AxisNumTicks); WmgAxisGraph.xAxis.axisLabels.Clear(); foreach (var datelist in date116.userRegisterDailyResponseVoList) { DateTime date = DateTime.Parse(datelist.registerDate); int month = date.Month; int day = date.Day; WmgAxisGraph.xAxis.axisLabels.Add($"{month}-{day}"); } WmgAxisGraph.yAxis.AxisNumTicks = date116.userRegisterDailyResponseVoList.Count;//y Debug.Log(WmgAxisGraph.yAxis.AxisNumTicks); long minValue = FindMinValue(); long maxValue = FindMaxValue(); Debug.Log(minValue); Debug.Log(maxValue); WmgAxisGraph.yAxis.axisLabels.Clear(); WmgAxisGraph.yAxis.axisLabels.Add($"{minValue}"); WmgAxisGraph.yAxis.axisLabels.Add($"{minValue+(maxValue-minValue)*0.5}"); WmgAxisGraph.yAxis.axisLabels.Add($"{maxValue}"); //point for (int i = 0; i < date116.userRegisterDailyResponseVoList.Count; i++) { WmgSeries.pointValues.Add(new Vector2(0, date116.userRegisterDailyResponseVoList[i].registerUser)); } } // Update is called once per frame void Update() { } public async Task OnClick116BpanelAsync() { // 准备请求的头部信息,包含授权令牌 Dictionary head116 = new Dictionary { { "Authorization", Global.global.serverResponse.data.token } }; // 异步发送请求 string response118 = await web.SendRequest(web.URL + "/snail/data/queryDaily", "GET", "{}", head116); // 调试输出接收到的响应 Debug.Log("1.16数据看板 =====================" + response118); // 将响应反序列化为 KnightRoomList 对象 Response116 directlist = JsonConvert.DeserializeObject(response118); // 检查反序列化是否成功 if (directlist != null && directlist.data != null) { Debug.Log("获取成功"); } else { Debug.LogError("directlist 数据为空"); } return directlist.data; } } public class Response116 : Response { public Date116 data; } public class Date116 { public List userRegisterDailyResponseVoList; public long userVoluteCoinCount; } public class datelist116 { public string registerDate; public long registerUser; }