Example04_DataZoom.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using UnityEngine;
  2. using XCharts.Runtime;
  3. namespace XCharts.Example
  4. {
  5. [DisallowMultipleComponent]
  6. [ExecuteInEditMode]
  7. public class Example04_DataZoom : MonoBehaviour
  8. {
  9. BaseChart chart;
  10. void Awake()
  11. {
  12. chart = gameObject.GetComponent<BaseChart>();
  13. if (chart == null) return;
  14. var dataZoom = chart.GetChartComponent<DataZoom>();
  15. if (dataZoom == null) return;
  16. dataZoom.marqueeStyle.onStart = OnMarqueeStart;
  17. dataZoom.marqueeStyle.onEnd = OnMarqueeEnd;
  18. dataZoom.marqueeStyle.onGoing = OnMarquee;
  19. }
  20. void OnMarqueeStart(DataZoom dataZoom)
  21. {
  22. //Debug.Log("OnMarqueeStart:" + dataZoom);
  23. }
  24. void OnMarquee(DataZoom dataZoom)
  25. {
  26. //Debug.Log("OnMarquee:" + dataZoom);
  27. }
  28. void OnMarqueeEnd(DataZoom dataZoom)
  29. {
  30. //Debug.Log("OnMarqueeEnd:" + dataZoom);
  31. var serie = chart.GetSerie(0);
  32. foreach (var serieData in serie.data)
  33. {
  34. if (dataZoom.IsInMarqueeArea(serieData))
  35. {
  36. serieData.GetOrAddComponent<ItemStyle>().color = Color.red;
  37. }
  38. else
  39. {
  40. serieData.GetOrAddComponent<ItemStyle>().color = Color.clear;
  41. }
  42. }
  43. }
  44. }
  45. }