AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
Example_Dynamic.cs
1 /************************************************/
2 /* */
3 /* Copyright (c) 2018 - 2021 monitor1394 */
4 /* https://github.com/monitor1394 */
5 /* */
6 /************************************************/
7 
8 using System;
9 using UnityEngine;
10 
11 namespace XCharts.Examples
12 {
13  [DisallowMultipleComponent]
14  [ExecuteInEditMode]
15  [RequireComponent(typeof(CoordinateChart))]
16  public class Example_Dynamic : MonoBehaviour
17  {
18  public int maxCacheDataNumber = 100;
19  public float initDataTime = 2;
20  public bool insertDataToHead = false;
21 
22  private CoordinateChart chart;
23  private float updateTime;
24  private float initTime;
25  private int initCount;
26  private int count;
27  private bool isInited;
28  private DateTime timeNow;
29 
30  void Awake()
31  {
32  chart = gameObject.GetComponentInChildren<CoordinateChart>();
33  chart.RemoveData();
34  var serie = chart.AddSerie(SerieType.Line);
35  serie.symbol.show = false;
36  serie.maxCache = maxCacheDataNumber;
37  chart.xAxes[0].maxCache = maxCacheDataNumber;
38  timeNow = DateTime.Now;
39  timeNow = timeNow.AddSeconds(-maxCacheDataNumber);
40 
41  serie.insertDataToHead = insertDataToHead;
42  chart.xAxes[0].insertDataToHead = insertDataToHead;
43  }
44 
45  void Update()
46  {
47  if (initCount < maxCacheDataNumber)
48  {
49  int count = (int)(maxCacheDataNumber / initDataTime * Time.deltaTime);
50  for (int i = 0; i < count; i++)
51  {
52  timeNow = timeNow.AddSeconds(1);
53  string category = timeNow.ToString("hh:mm:ss");
54  float value = UnityEngine.Random.Range(60, 150);
55  chart.AddXAxisData(category);
56  chart.AddData(0, value);
57  initCount++;
58  if (initCount > maxCacheDataNumber) break;
59  }
60  chart.RefreshChart();
61  }
62  updateTime += Time.deltaTime;
63  if (updateTime >= 1)
64  {
65  updateTime = 0;
66  count++;
67  string category = DateTime.Now.ToString("hh:mm:ss");
68  float value = UnityEngine.Random.Range(60, 150);
69  chart.AddXAxisData(category);
70  chart.AddData(0, value);
71  chart.RefreshChart();
72  }
73  }
74  }
75 }
XCharts.CoordinateChart.RemoveData
override void RemoveData()
Remove all data from series,legend and axis. The series list is also cleared. 清空所有图例,系列和坐标轴类目数据。系列的列表...
Definition: CoordinateChart_API.cs:71
XCharts.SerieType
SerieType
the type of serie. 系列类型。
Definition: Serie.cs:19
XCharts.CoordinateChart.AddXAxisData
void AddXAxisData(string category, int xAxisIndex=0)
Add a category data to xAxis. 添加一个类目数据到指定的x轴。
Definition: CoordinateChart_API.cs:101
XCharts.Examples
Definition: RewardChart.cs:14
XCharts.CoordinateChart.xAxes
List< XAxis > xAxes
the x Axes,xAxes[0] is the first x axis, xAxes[1] is the second x axis. 两个x轴。
Definition: CoordinateChart_API.cs:30
XCharts.Examples.Example_Dynamic
Definition: Example_Dynamic.cs:16
XCharts.CoordinateChart
The basic class of rectangular coordinate chart,such as LineChart,BarChart and ScatterChart....
Definition: CoordinateChart_API.cs:18