实现跟随坐标轴移动捕获顶点
代码如下:
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using XCharts.Runtime;
public class Demo : MonoBehaviour
{
public Image tag;
public int index;
private BaseChart chart;
private void Awake()
{
chart = this.GetComponent<BaseChart>();
}
private void Update()
{
tag.transform.position = chart.GetPos(0, index);
}
}
public static class ChartHelper
{
public static Vector2 GetPos(this BaseChart chart, int serie, int index)
{
(double, double) pair;
List<SerieData> dataList;
dataList = chart.GetSerie(serie).GetDataList();
if (index < dataList.Count)
{
pair = (dataList[index].data[0], dataList[index].data[1]);
float x0 = AxisHelper.GetAxisPosition(chart.GetChartComponent<GridCoord>(),
chart.GetChartComponent<XAxis>(),
pair.Item1);
float y0 = AxisHelper.GetAxisPosition(chart.GetChartComponent<GridCoord>(),
chart.GetChartComponent<YAxis>(),
pair.Item2);
return new Vector3(x0, y0) + chart.transform.position;
}
else
{
Debug.LogError("index越界");
return Vector2.zero;
}
}
}