Files
XCharts/Demo.cs

39 lines
1.2 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;
public class Demo : MonoBehaviour
{
private LineChart lineChart;
private float time;
2018-09-21 22:30:48 +08:00
private int count;
2018-09-15 06:52:42 +08:00
2018-09-21 22:30:48 +08:00
void Awake()
{
2018-09-23 08:18:26 +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 = xchart.GetComponent<RectTransform>();
var wid = rect.sizeDelta.x;
int childNum = xchart.childCount;
int numWid =(int) ((wid - grid.padding.left - grid.padding.right) / (grid.cellSize.x+grid.spacing.x));
int numHig = (childNum + numWid - 1) / numWid;
float hig = grid.padding.top + numHig * (grid.cellSize.y+ grid.spacing.y);
rect.sizeDelta = new Vector2(wid,hig);
2018-09-15 06:52:42 +08:00
}
2018-09-21 22:30:48 +08:00
void Update()
{
2018-09-15 06:52:42 +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-15 06:52:42 +08:00
}
}
}