Example_LargeData.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using UnityEngine;
  2. using XCharts.Runtime;
  3. namespace XCharts.Example
  4. {
  5. [DisallowMultipleComponent]
  6. [ExecuteInEditMode]
  7. [RequireComponent(typeof(BaseChart))]
  8. public class Example_LargeData : MonoBehaviour
  9. {
  10. public int maxCacheDataNumber = 1000;
  11. public float initDataTime = 5;
  12. private BaseChart chart;
  13. private float initTime;
  14. private int initCount = 0;
  15. private System.DateTime timeNow;
  16. void Awake()
  17. {
  18. chart = gameObject.GetComponentInChildren<BaseChart>();
  19. timeNow = System.DateTime.Now;
  20. chart.ClearData();
  21. chart.SetMaxCache(maxCacheDataNumber);
  22. chart.GetChartComponent<Title>().text = maxCacheDataNumber + "数据";
  23. }
  24. private double lastValue = 0d;
  25. private void Update()
  26. {
  27. if (initCount < maxCacheDataNumber)
  28. {
  29. for (int i = 0; i < 20; i++)
  30. {
  31. initCount++;
  32. if (initCount > maxCacheDataNumber) break;
  33. chart.GetChartComponent<Title>().text = initCount + "数据";
  34. timeNow = timeNow.AddSeconds(1);
  35. if (lastValue < 20)
  36. lastValue += UnityEngine.Random.Range(0, 5);
  37. else
  38. lastValue += UnityEngine.Random.Range(-5f, 5f);
  39. chart.AddData(0, lastValue);
  40. chart.AddXAxisData(timeNow.ToString("hh:mm:ss"));
  41. }
  42. }
  43. }
  44. }
  45. }