Files
XCharts/Assets/Demo.cs

55 lines
1.5 KiB
C#
Raw Normal View History

2018-09-15 06:52:42 +08:00
using UnityEngine;
2018-09-25 07:33:04 +08:00
using UnityEngine.UI;
2018-09-15 06:52:42 +08:00
using xcharts;
2018-09-12 07:27:22 +08:00
public class Demo : MonoBehaviour
{
2018-10-02 08:57:47 +08:00
public Theme theme = Theme.Dark;
2018-09-12 07:27:22 +08:00
private LineChart lineChart;
private float time;
2018-09-21 22:30:48 +08:00
private int count;
2018-10-02 08:57:47 +08:00
private Theme checkTheme = Theme.Dark;
2018-09-12 07:27:22 +08:00
2018-09-21 22:30:48 +08:00
void Awake()
{
2019-03-12 08:10:25 +08:00
//lineChart = transform.Find("xchart/line_chart").GetComponent<LineChart>();
2018-09-25 07:33:04 +08:00
var xchart = transform.Find("xchart");
GridLayoutGroup grid = xchart.GetComponent<GridLayoutGroup>();
RectTransform rect = transform.GetComponent<RectTransform>();
2018-09-25 07:33:04 +08:00
var wid = rect.sizeDelta.x;
int childNum = xchart.childCount;
float hig = grid.padding.top + childNum * (grid.cellSize.y+ grid.spacing.y);
2018-09-25 07:33:04 +08:00
rect.sizeDelta = new Vector2(wid,hig);
xchart.GetComponent<RectTransform>().sizeDelta = new Vector2(wid, hig);
2018-09-12 07:27:22 +08:00
}
2018-09-21 22:30:48 +08:00
void Update()
{
2018-09-12 07:27:22 +08:00
time += Time.deltaTime;
if (time >= 1)
{
time = 0;
2018-09-21 22:30:48 +08:00
count++;
2018-09-26 09:06:23 +08:00
//lineChart.AddXAxisCategory("key" + count);
//lineChart.AddData("line1", "key"+count, Random.Range(24.0f, 60.0f));
//lineChart.AddData("line2", "key"+count, Random.Range(24.0f, 60.0f));
2018-09-12 07:27:22 +08:00
}
2018-10-02 08:57:47 +08:00
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);
}
2018-09-12 07:27:22 +08:00
}
}