mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-23 01:10:08 +00:00
代码整理,接口优化
This commit is contained in:
39
Demo/Scripts/Demo10_LineSimple.cs
Normal file
39
Demo/Scripts/Demo10_LineSimple.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using UnityEngine;
|
||||
using XCharts;
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
[ExecuteInEditMode]
|
||||
public class Demo10_LineSimple : MonoBehaviour
|
||||
{
|
||||
void Awake()
|
||||
{
|
||||
var chart = gameObject.GetComponent<LineChart>();
|
||||
if (chart == null) return;
|
||||
|
||||
chart.title.show = true;
|
||||
chart.title.text = "Line Simple";
|
||||
|
||||
chart.tooltip.show = true;
|
||||
chart.legend.show = false;
|
||||
|
||||
chart.xAxises[0].show = true;
|
||||
chart.xAxises[1].show = false;
|
||||
chart.yAxises[0].show = true;
|
||||
chart.yAxises[1].show = false;
|
||||
|
||||
chart.xAxises[0].type = Axis.AxisType.Category;
|
||||
chart.yAxises[0].type = Axis.AxisType.Value;
|
||||
|
||||
int dataCount = 10;
|
||||
chart.xAxises[0].splitNumber = dataCount;
|
||||
chart.xAxises[0].boundaryGap = true;
|
||||
|
||||
chart.RemoveData();
|
||||
chart.AddSerie("test", SerieType.Line);
|
||||
for (int i = 0; i < dataCount; i++)
|
||||
{
|
||||
chart.AddXAxisData("x" + i);
|
||||
chart.AddData(0, Random.Range(10, 20));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79b834e804f7aa844bc2ad80cf2bda9f
|
||||
timeCreated: 1557366438
|
||||
licenseType: Free
|
||||
guid: 75496d488607d421fbf2c190f80ed0a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -21,8 +21,8 @@ public class Demo_Dynamic : MonoBehaviour
|
||||
void Awake()
|
||||
{
|
||||
chart = gameObject.GetComponentInChildren<CoordinateChart>();
|
||||
chart.ClearAxisData();
|
||||
chart.series.ClearData();
|
||||
chart.RemoveData();
|
||||
chart.AddSerie("data", SerieType.Line);
|
||||
chart.maxCacheDataNumber = maxCacheDataNumber;
|
||||
timeNow = DateTime.Now;
|
||||
timeNow = timeNow.AddSeconds(-maxCacheDataNumber);
|
||||
@@ -30,14 +30,16 @@ public class Demo_Dynamic : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (initCount< maxCacheDataNumber)
|
||||
if (initCount < maxCacheDataNumber)
|
||||
{
|
||||
int count = (int)(maxCacheDataNumber / initDataTime * Time.deltaTime);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
timeNow = timeNow.AddSeconds(1);
|
||||
chart.AddXAxisData(timeNow.ToString("hh:mm:ss"));
|
||||
chart.AddData(0, UnityEngine.Random.Range(60, 150));
|
||||
string category = timeNow.ToString("hh:mm:ss");
|
||||
float value = UnityEngine.Random.Range(60, 150);
|
||||
chart.AddXAxisData(category);
|
||||
chart.AddData(0, value);
|
||||
initCount++;
|
||||
if (initCount > maxCacheDataNumber) break;
|
||||
}
|
||||
@@ -48,8 +50,10 @@ public class Demo_Dynamic : MonoBehaviour
|
||||
{
|
||||
updateTime = 0;
|
||||
count++;
|
||||
chart.AddXAxisData(DateTime.Now.ToString("hh:mm:ss"));
|
||||
chart.AddData(0, UnityEngine.Random.Range(60, 150));
|
||||
string category = DateTime.Now.ToString("hh:mm:ss");
|
||||
float value = UnityEngine.Random.Range(60, 150);
|
||||
chart.AddXAxisData(category);
|
||||
chart.AddData(0, value);
|
||||
chart.RefreshChart();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,34 +37,6 @@ public class Demo_LargeData : MonoBehaviour
|
||||
initCount++;
|
||||
if (initCount > maxCacheDataNumber) break;
|
||||
}
|
||||
chart.RefreshChart();
|
||||
}
|
||||
}
|
||||
|
||||
void GenerateData(int count, CoordinateChart chart)
|
||||
{
|
||||
var baseValue = Random.Range(0, 1000);
|
||||
var time = new System.DateTime(2011, 1, 1);
|
||||
var smallBaseValue = 0;
|
||||
|
||||
chart.xAxises[0].ClearData();
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
chart.AddXAxisData(time.ToString("hh:mm:ss"));
|
||||
|
||||
smallBaseValue = i % 30 == 0
|
||||
? Random.Range(0, 700)
|
||||
: (smallBaseValue + Random.Range(0, 500) - 250);
|
||||
baseValue += Random.Range(0, 20) - 10;
|
||||
float value = Mathf.Max(
|
||||
0,
|
||||
Mathf.Round(baseValue + smallBaseValue) + 3000
|
||||
);
|
||||
//var index = i % 100;
|
||||
//var value = (Mathf.Sin(index / 5) * (index / 5 - 10) + index / 6) * 5;
|
||||
value = Mathf.Abs(value);
|
||||
chart.AddData(0, value);
|
||||
time = time.AddSeconds(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
using UnityEngine;
|
||||
using XCharts;
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
[ExecuteInEditMode]
|
||||
//[RequireComponent(typeof(CoordinateChart))]
|
||||
public class Demo_Test : MonoBehaviour
|
||||
{
|
||||
private CoordinateChart chart;
|
||||
private float time;
|
||||
private int count;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
chart = gameObject.GetComponentInChildren<CoordinateChart>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
if (time >= 1)
|
||||
{
|
||||
time = 0;
|
||||
count++;
|
||||
chart.UpdateData(0, Random.Range(60, 150));
|
||||
chart.AddXAxisData("time" + count);
|
||||
chart.AddData(0, Random.Range(60, 150));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user