2021-12-24 13:33:09 +08:00
|
|
|
|
|
2019-10-22 04:09:04 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
2021-12-24 13:33:09 +08:00
|
|
|
|
namespace XCharts.Example
|
2019-10-22 04:09:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
[DisallowMultipleComponent]
|
2022-01-26 20:47:14 +08:00
|
|
|
|
[ExecuteInEditMode]
|
2021-11-23 13:20:07 +08:00
|
|
|
|
[RequireComponent(typeof(BaseChart))]
|
2020-05-15 06:52:40 +08:00
|
|
|
|
public class Example_LargeData : MonoBehaviour
|
2019-10-22 04:09:04 +08:00
|
|
|
|
{
|
2022-01-26 20:47:14 +08:00
|
|
|
|
public int maxCacheDataNumber = 1000;
|
2019-10-22 04:09:04 +08:00
|
|
|
|
public float initDataTime = 5;
|
|
|
|
|
|
|
2021-11-23 13:20:07 +08:00
|
|
|
|
private BaseChart chart;
|
2019-10-22 04:09:04 +08:00
|
|
|
|
private float initTime;
|
|
|
|
|
|
private int initCount = 0;
|
|
|
|
|
|
private System.DateTime timeNow;
|
|
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
|
{
|
2021-11-23 13:20:07 +08:00
|
|
|
|
chart = gameObject.GetComponentInChildren<BaseChart>();
|
2019-10-22 04:09:04 +08:00
|
|
|
|
timeNow = System.DateTime.Now;
|
2021-11-23 13:20:07 +08:00
|
|
|
|
chart.ClearData();
|
2020-05-13 09:54:40 +08:00
|
|
|
|
chart.SetMaxCache(maxCacheDataNumber);
|
2021-11-23 13:20:07 +08:00
|
|
|
|
chart.GetChartComponent<Title>().text = maxCacheDataNumber + "数据";
|
2019-10-22 04:09:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-05 07:46:30 +08:00
|
|
|
|
private double lastValue = 0d;
|
|
|
|
|
|
|
2019-10-22 04:09:04 +08:00
|
|
|
|
private void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (initCount < maxCacheDataNumber)
|
|
|
|
|
|
{
|
2022-01-05 07:46:30 +08:00
|
|
|
|
for (int i = 0; i < 20; i++)
|
2019-10-22 04:09:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
initCount++;
|
|
|
|
|
|
if (initCount > maxCacheDataNumber) break;
|
2021-11-23 13:20:07 +08:00
|
|
|
|
chart.GetChartComponent<Title>().text = initCount + "数据";
|
2022-01-05 07:46:30 +08:00
|
|
|
|
|
2019-10-22 04:09:04 +08:00
|
|
|
|
timeNow = timeNow.AddSeconds(1);
|
2022-01-05 07:46:30 +08:00
|
|
|
|
if (lastValue < 20)
|
|
|
|
|
|
lastValue += UnityEngine.Random.Range(0, 5);
|
|
|
|
|
|
else
|
|
|
|
|
|
lastValue += UnityEngine.Random.Range(-5f, 5f);
|
|
|
|
|
|
chart.AddData(0, lastValue);
|
2019-10-22 04:09:04 +08:00
|
|
|
|
|
|
|
|
|
|
chart.AddXAxisData(timeNow.ToString("hh:mm:ss"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|