Example13_LineSimple.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using UnityEngine;
  2. #if INPUT_SYSTEM_ENABLED
  3. using Input = XCharts.Runtime.InputHelper;
  4. #endif
  5. using XCharts.Runtime;
  6. namespace XCharts.Example
  7. {
  8. [DisallowMultipleComponent]
  9. [ExecuteInEditMode]
  10. public class Example13_LineSimple : MonoBehaviour
  11. {
  12. void Awake()
  13. {
  14. AddData();
  15. }
  16. void Update()
  17. {
  18. if (Input.GetKeyDown(KeyCode.Space))
  19. {
  20. AddData();
  21. }
  22. }
  23. void AddData()
  24. {
  25. var chart = gameObject.GetComponent<LineChart>();
  26. if (chart == null)
  27. {
  28. chart = gameObject.AddComponent<LineChart>();
  29. chart.Init();
  30. }
  31. chart.EnsureChartComponent<Title>().show = true;
  32. chart.EnsureChartComponent<Title>().text = "Line Simple";
  33. chart.EnsureChartComponent<Tooltip>().show = true;
  34. chart.EnsureChartComponent<Legend>().show = false;
  35. var xAxis = chart.EnsureChartComponent<XAxis>();
  36. var yAxis = chart.EnsureChartComponent<YAxis>();
  37. xAxis.show = true;
  38. yAxis.show = true;
  39. xAxis.type = Axis.AxisType.Category;
  40. yAxis.type = Axis.AxisType.Value;
  41. xAxis.splitNumber = 10;
  42. xAxis.boundaryGap = true;
  43. chart.RemoveData();
  44. chart.AddSerie<Line>();
  45. chart.AddSerie<Line>();
  46. for (int i = 0; i < 20; i++)
  47. {
  48. chart.AddXAxisData("x" + i);
  49. chart.AddData(0, Random.Range(10, 20));
  50. chart.AddData(1, Random.Range(10, 20));
  51. }
  52. }
  53. }
  54. }