Example01_UpdateData.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using UnityEngine;
  2. using XCharts.Runtime;
  3. namespace XCharts.Example
  4. {
  5. [DisallowMultipleComponent]
  6. [ExecuteInEditMode]
  7. public class Example01_UpdateData : MonoBehaviour
  8. {
  9. private float updateTime = 0;
  10. BaseChart chart;
  11. void Awake()
  12. {
  13. chart = gameObject.GetComponent<BaseChart>();
  14. }
  15. void Update()
  16. {
  17. updateTime += Time.deltaTime;
  18. if (chart && updateTime > 2)
  19. {
  20. updateTime = 0;
  21. var serie = chart.GetSerie(0);
  22. //serie.animation.dataChangeEnable = true;
  23. var dataCount = serie.dataCount;
  24. if (chart is RadarChart)
  25. {
  26. var dimension = serie.GetSerieData(0).data.Count - 1;
  27. chart.UpdateData(0, 0, Random.Range(0, dimension + 1), Random.Range(0, 100));
  28. }
  29. else if (chart is HeatmapChart)
  30. {
  31. var dimension = serie.GetSerieData(0).data.Count - 1;
  32. for (int i = 0; i < dataCount; i++)
  33. {
  34. chart.UpdateData(0, i, dimension, Random.Range(0, 10));
  35. }
  36. }
  37. else
  38. {
  39. chart.UpdateData(0, Random.Range(0, dataCount), Random.Range(10, 90));
  40. }
  41. }
  42. }
  43. }
  44. }