No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Example11_AddSinCurve.cs 1.7KB

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