mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-15 21:00:11 +00:00
3.0
This commit is contained in:
52
Examples/Example_LargeData.cs
Normal file
52
Examples/Example_LargeData.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
namespace XCharts.Example
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(BaseChart))]
|
||||
public class Example_LargeData : MonoBehaviour
|
||||
{
|
||||
public int maxCacheDataNumber = 1000;
|
||||
public float initDataTime = 5;
|
||||
|
||||
private BaseChart chart;
|
||||
private float initTime;
|
||||
private int initCount = 0;
|
||||
private System.DateTime timeNow;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
chart = gameObject.GetComponentInChildren<BaseChart>();
|
||||
timeNow = System.DateTime.Now;
|
||||
chart.ClearData();
|
||||
chart.SetMaxCache(maxCacheDataNumber);
|
||||
chart.GetChartComponent<Title>().text = maxCacheDataNumber + "数据";
|
||||
}
|
||||
|
||||
private double lastValue = 0d;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (initCount < maxCacheDataNumber)
|
||||
{
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
initCount++;
|
||||
if (initCount > maxCacheDataNumber) break;
|
||||
chart.GetChartComponent<Title>().text = initCount + "数据";
|
||||
|
||||
timeNow = timeNow.AddSeconds(1);
|
||||
if (lastValue < 20)
|
||||
lastValue += UnityEngine.Random.Range(0, 5);
|
||||
else
|
||||
lastValue += UnityEngine.Random.Range(-5f, 5f);
|
||||
chart.AddData(0, lastValue);
|
||||
|
||||
chart.AddXAxisData(timeNow.ToString("hh:mm:ss"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user