Example11_AddSinCurve.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using UnityEngine;
  2. using XCharts.Runtime;
  3. namespace XCharts.Example
  4. {
  5. [DisallowMultipleComponent]
  6. [ExecuteInEditMode]
  7. public class Example11_AddSinCurve : MonoBehaviour
  8. {
  9. private float time;
  10. public int angle;
  11. private LineChart chart;
  12. void Awake()
  13. {
  14. chart = gameObject.GetComponent<LineChart>();
  15. if (chart == null)
  16. {
  17. chart = gameObject.AddComponent<LineChart>();
  18. }
  19. chart.GetChartComponent<Title>().show = true;
  20. chart.GetChartComponent<Title>().text = "Sin Curve";
  21. chart.GetChartComponent<Tooltip>().show = true;
  22. chart.GetChartComponent<Legend>().show = false;
  23. var xAxis = chart.GetChartComponent<XAxis>();
  24. var yAxis = chart.GetChartComponent<YAxis>();
  25. xAxis.show = true;
  26. yAxis.show = true;
  27. xAxis.type = Axis.AxisType.Value;
  28. yAxis.type = Axis.AxisType.Value;
  29. xAxis.boundaryGap = false;
  30. xAxis.maxCache = 0;
  31. chart.series[0].maxCache = 0;
  32. chart.RemoveData();
  33. var serie = chart.AddSerie<Line>();
  34. serie.symbol.show = false;
  35. serie.lineType = LineType.Normal;
  36. for (angle = 0; angle < 1080; angle++)
  37. {
  38. float xvalue = Mathf.PI / 180 * angle;
  39. float yvalue = Mathf.Sin(xvalue);
  40. chart.AddData(0, xvalue, yvalue);
  41. }
  42. }
  43. void Update()
  44. {
  45. if (angle > 3000) return;
  46. angle++;
  47. float xvalue = Mathf.PI / 180 * angle;
  48. float yvalue = Mathf.Sin(xvalue);
  49. chart.AddData(0, xvalue, yvalue);
  50. }
  51. }
  52. }