70 lines
2.6 KiB
C#
70 lines
2.6 KiB
C#
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using TMPro;
|
||
|
|
using UnityEngine;
|
||
|
|
using XCharts.Runtime;
|
||
|
|
|
||
|
|
// 温湿度趋势图
|
||
|
|
public class HumitureTrend_Controller : MonoBehaviour
|
||
|
|
{
|
||
|
|
private LineChart lineChart;
|
||
|
|
private EMIMS_Data emimsData;
|
||
|
|
|
||
|
|
|
||
|
|
void OnEnable()
|
||
|
|
{
|
||
|
|
lineChart = gameObject.GetComponent<LineChart>();
|
||
|
|
emimsData = new EMIMS_Data();
|
||
|
|
List<EM_Data> list = new List<EM_Data>
|
||
|
|
{
|
||
|
|
new EM_Data {ID = "1", Name = "温度一天前", DataType = "float", Value = 14.5f},
|
||
|
|
new EM_Data {ID = "2", Name = "温度两天前", DataType = "float", Value = 26.2f},
|
||
|
|
new EM_Data {ID = "3", Name = "温度三天前", DataType = "float", Value = 18.7f},
|
||
|
|
new EM_Data {ID = "4", Name = "温度四天前", DataType = "float", Value = 22.1f},
|
||
|
|
new EM_Data {ID = "5", Name = "温度五天前", DataType = "float", Value = 16.9f},
|
||
|
|
new EM_Data {ID = "6", Name = "温度六天前", DataType = "float", Value = 20.3f},
|
||
|
|
new EM_Data {ID = "7", Name = "温度七天前", DataType = "float", Value = 19.8f},
|
||
|
|
|
||
|
|
new EM_Data {ID = "8", Name = "湿度一天前", DataType = "float", Value = 41.2f},
|
||
|
|
new EM_Data {ID = "9", Name = "湿度两天前", DataType = "float", Value = 54.5f},
|
||
|
|
new EM_Data {ID = "10", Name = "湿度三天前", DataType = "float", Value = 22.8f},
|
||
|
|
new EM_Data {ID = "11", Name = "湿度四天前", DataType = "float", Value = 43.1f},
|
||
|
|
new EM_Data {ID = "12", Name = "湿度五天前", DataType = "float", Value = 21.9f},
|
||
|
|
new EM_Data {ID = "13", Name = "湿度六天前", DataType = "float", Value = 42.3f},
|
||
|
|
new EM_Data {ID = "14", Name = "湿度七天前", DataType = "float", Value = 50.8f},
|
||
|
|
};
|
||
|
|
emimsData.Tags = list;
|
||
|
|
|
||
|
|
StartCoroutine(UpdateDataSource());
|
||
|
|
}
|
||
|
|
|
||
|
|
public IEnumerator UpdateDataSource()
|
||
|
|
{
|
||
|
|
while (true)
|
||
|
|
{
|
||
|
|
emimsData.Tags[Random.Range(0,7)].Value = Random.Range(10f,40f);
|
||
|
|
emimsData.Tags[Random.Range(7,14)].Value = Random.Range(30f,80f);
|
||
|
|
UpdateDataView();
|
||
|
|
yield return new WaitForSeconds(4f);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 更新填充数据
|
||
|
|
private void UpdateDataView()
|
||
|
|
{
|
||
|
|
lineChart.ClearSerieData();
|
||
|
|
|
||
|
|
for (int i = 0; i < 7; i++)
|
||
|
|
{
|
||
|
|
lineChart.series[0].AddData(i, (float)emimsData.Tags[i].Value);
|
||
|
|
}
|
||
|
|
|
||
|
|
for (int i = 7; i < 14; i++)
|
||
|
|
{
|
||
|
|
lineChart.series[1].AddData(i, (float)emimsData.Tags[i].Value);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|