mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-24 18:00:26 +00:00
优化坐标绘制,支持大数据
This commit is contained in:
52
Demo/Demo.cs
Normal file
52
Demo/Demo.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using xcharts;
|
||||
|
||||
public class Demo : MonoBehaviour
|
||||
{
|
||||
public Theme theme = Theme.Dark;
|
||||
|
||||
private BaseChart chart;
|
||||
private float time;
|
||||
private int count;
|
||||
private Theme checkTheme = Theme.Dark;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
var xchart = transform.Find("xchart");
|
||||
GridLayoutGroup grid = xchart.GetComponent<GridLayoutGroup>();
|
||||
RectTransform rect = transform.GetComponent<RectTransform>();
|
||||
var wid = rect.sizeDelta.x;
|
||||
int childNum = xchart.childCount;
|
||||
float hig = grid.padding.top + childNum * (grid.cellSize.y + grid.spacing.y);
|
||||
rect.sizeDelta = new Vector2(wid, hig);
|
||||
xchart.GetComponent<RectTransform>().sizeDelta = new Vector2(wid, hig);
|
||||
|
||||
chart = xchart.gameObject.GetComponentInChildren<BaseChart>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
if (time >= 1)
|
||||
{
|
||||
time = 0;
|
||||
count++;
|
||||
chart.UpdateData(0, Random.RandomRange(60, 150));
|
||||
}
|
||||
if (checkTheme != theme)
|
||||
{
|
||||
checkTheme = theme;
|
||||
UpdateTheme(theme);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateTheme(Theme theme)
|
||||
{
|
||||
var charts = transform.Find("xchart").GetComponentsInChildren<BaseChart>();
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
chart.UpdateTheme(theme);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user