Example_Test.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using XCharts.Runtime;
  4. namespace XCharts.Example
  5. {
  6. [DisallowMultipleComponent]
  7. [ExecuteInEditMode]
  8. public class Example_Test : MonoBehaviour
  9. {
  10. BaseChart chart;
  11. void Awake()
  12. {
  13. chart = gameObject.GetComponent<BaseChart>();
  14. var btnTrans = transform.parent.Find("Button");
  15. if (btnTrans)
  16. {
  17. btnTrans.gameObject.GetComponent<Button>().onClick.AddListener(OnTestBtn);
  18. }
  19. }
  20. void Update()
  21. {
  22. if (Input.GetKeyDown(KeyCode.Space))
  23. {
  24. AddData();
  25. //OnTestBtn();
  26. }
  27. }
  28. void OnTestBtn()
  29. {
  30. object[][] m_TestData = new object[][]
  31. {
  32. new object[] { "01/06/20", 2.2d, 5.6d },
  33. new object[] { "22/06/20", 2.4d, 5.3d },
  34. new object[] { "04/08/21", 4.5d, 5.4d },
  35. new object[] { "05/08/21", 6.3d, 6.4d },
  36. new object[] { "06/08/21", 3.1d, 6.4d },
  37. new object[] { "09/08/21", 3.9d, 6.3d },
  38. new object[] { "10/08/21", 1.9d, 4.6d },
  39. };
  40. chart.ClearData();
  41. foreach (var list in m_TestData)
  42. {
  43. chart.AddXAxisData((string) list[0]);
  44. chart.AddData(0, (double) list[1]);
  45. chart.AddData(1, (double) list[2]);
  46. }
  47. }
  48. void AddData()
  49. {
  50. var serie = chart.InsertSerie<Bar>(0);
  51. for(int i=0;i<5;i++){
  52. chart.AddData(serie.index, Random.Range(10,90));
  53. }
  54. }
  55. }
  56. }