Example12_CustomDrawing.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using XCharts.Runtime;
  4. using XUGL;
  5. namespace XCharts.Example
  6. {
  7. [DisallowMultipleComponent]
  8. [ExecuteInEditMode]
  9. public class Example12_CustomDrawing : MonoBehaviour
  10. {
  11. LineChart chart;
  12. void Awake()
  13. {
  14. chart = gameObject.GetComponent<LineChart>();
  15. if (chart == null) return;
  16. chart.onDraw = delegate(VertexHelper vh) { };
  17. // or
  18. chart.onDrawBeforeSerie = delegate(VertexHelper vh, Serie serie) { };
  19. // or
  20. chart.onDrawAfterSerie = delegate(VertexHelper vh, Serie serie)
  21. {
  22. if (serie.index != 0) return;
  23. var dataPoints = serie.context.dataPoints;
  24. if (dataPoints.Count > 0)
  25. {
  26. var pos = dataPoints[3];
  27. var grid = chart.GetChartComponent<GridCoord>();
  28. var zeroPos = new Vector3(grid.context.x, grid.context.y);
  29. var startPos = new Vector3(pos.x, zeroPos.y);
  30. var endPos = new Vector3(pos.x, zeroPos.y + grid.context.height);
  31. UGL.DrawLine(vh, startPos, endPos, chart.theme.serie.lineWidth, Color.blue);
  32. UGL.DrawCricle(vh, pos, 5, Color.blue);
  33. }
  34. };
  35. // or
  36. chart.onDrawTop = delegate(VertexHelper vh) { };
  37. }
  38. }
  39. }