AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
Example00_CheatSheet.cs
1 /************************************************/
2 /* */
3 /* Copyright (c) 2018 - 2021 monitor1394 */
4 /* https://github.com/monitor1394 */
5 /* */
6 /************************************************/
7 
8 using System.Collections;
9 using System.Collections.Generic;
10 using UnityEngine;
11 
12 namespace XCharts.Examples
13 {
14  [DisallowMultipleComponent]
15  public class Example00_CheatSheet : MonoBehaviour
16  {
17  private LineChart chart;
18  private float speed = 100f;
19 
20  void Awake()
21  {
22  LoopDemo();
23  }
24 
25  private void OnEnable()
26  {
27  LoopDemo();
28  }
29 
30  void LoopDemo()
31  {
32  StopAllCoroutines();
33  StartCoroutine(CheatSheet());
34  }
35 
36  IEnumerator CheatSheet()
37  {
38  StartCoroutine(InitChart());
39  StartCoroutine(ComponentTitle());
40  yield return new WaitForSeconds(2);
41  StartCoroutine(ComponentAxis());
42  yield return new WaitForSeconds(2);
43  StartCoroutine(ComponentGrid());
44  yield return new WaitForSeconds(2);
45  StartCoroutine(ComponentSerie());
46  yield return new WaitForSeconds(4);
47  StartCoroutine(ComponentLegend());
48  yield return new WaitForSeconds(4);
49  StartCoroutine(ComponentTheme());
50  yield return new WaitForSeconds(4);
51  StartCoroutine(ComponentDataZoom());
52  yield return new WaitForSeconds(5);
53  StartCoroutine(ComponentVisualMap());
54  yield return new WaitForSeconds(3);
55  LoopDemo();
56  }
57 
58  IEnumerator InitChart()
59  {
60  chart = gameObject.GetComponent<LineChart>();
61  if (chart == null) gameObject.AddComponent<LineChart>();
62 
63  chart.title.show = true;
64  chart.title.text = "术语解析-组件";
65  chart.grid.bottom = 30;
66  chart.grid.right = 30;
67  chart.grid.left = 50;
68  chart.grid.top = 80;
69 
70  chart.dataZooms[0].enable = false;
71  chart.visualMap.enable = false;
72 
73  chart.RemoveData();
74 
75  chart.AddSerie(SerieType.Bar, "Bar");
76  chart.AddSerie(SerieType.Line, "Line");
77 
78  for (int i = 0; i < 8; i++)
79  {
80  chart.AddXAxisData("x" + (i + 1));
81  chart.AddData(0, Random.Range(10, 100));
82  chart.AddData(1, Random.Range(30, 100));
83  }
84  yield return null;
85  }
86 
87  IEnumerator ComponentTitle()
88  {
89  chart.title.text = "术语解析 - 组件";
90  chart.title.subText = "Title 标题:可指定主标题和子标题";
91  chart.xAxis0.show = true;
92  chart.yAxis0.show = true;
93  chart.series.list[0].show = false;
94  chart.series.list[1].show = false;
95  chart.legend.show = false;
96  for (int i = 0; i < 4; i++)
97  {
98  chart.title.show = !chart.title.show;
99  chart.RefreshChart();
100  yield return new WaitForSeconds(0.2f);
101  }
102  chart.title.show = true;
103  chart.RefreshChart();
104  }
105 
106  IEnumerator ComponentAxis()
107  {
108  chart.title.subText = "Axis 坐标轴:配置X和Y轴的轴线、刻度、标签等样式外观配置";
109  chart.series.list[0].show = false;
110  chart.series.list[1].show = false;
111  for (int i = 0; i < 4; i++)
112  {
113  chart.xAxis0.show = !chart.xAxis0.show;
114  chart.yAxis0.show = !chart.yAxis0.show;
115  chart.RefreshChart();
116  yield return new WaitForSeconds(0.2f);
117  }
118  chart.xAxis0.show = true;
119  chart.yAxis0.show = true;
120  chart.RefreshChart();
121  yield return new WaitForSeconds(1f);
122  }
123 
124  IEnumerator ComponentGrid()
125  {
126  chart.title.subText = "Grid 网格:调整坐标系边距和颜色等";
127  for (int i = 0; i < 4; i++)
128  {
129  chart.grid.backgroundColor = i % 2 == 0 ? Color.clear : Color.grey;
130  chart.RefreshChart();
131  yield return new WaitForSeconds(0.2f);
132  }
133  chart.grid.backgroundColor = Color.clear;
134  chart.RefreshChart();
135  yield return new WaitForSeconds(1f);
136  }
137 
138  IEnumerator ComponentSerie()
139  {
140  chart.title.subText = "Serie 系列:调整坐标系边距和颜色等";
141  chart.series.list[0].show = true;
142  chart.series.list[1].show = true;
143  chart.AnimationReset();
144  chart.RefreshChart();
145  yield return new WaitForSeconds(1.2f);
146  for (int i = 0; i < 4; i++)
147  {
148  chart.series.list[0].show = !chart.series.list[0].show;
149  chart.series.list[1].show = !chart.series.list[1].show;
150  chart.RefreshChart();
151  yield return new WaitForSeconds(0.2f);
152  }
153  chart.series.list[0].show = true;
154  chart.series.list[1].show = true;
155  chart.RefreshChart();
156  yield return new WaitForSeconds(1f);
157  }
158 
159  IEnumerator ComponentLegend()
160  {
161  chart.title.subText = "Legend 图例:展示不同系列的名字和颜色,可控制系列显示等";
162  chart.legend.show = true;
163  chart.grid.top = 80;
164  chart.legend.location.top = 50;
165  chart.RefreshChart();
166  yield return new WaitForSeconds(1f);
167  for (int i = 0; i < 4; i++)
168  {
169  chart.legend.show = !chart.legend.show;
170  chart.RefreshChart();
171  yield return new WaitForSeconds(0.2f);
172  }
173  chart.legend.show = true;
174  chart.RefreshChart();
175  yield return new WaitForSeconds(1f);
176  chart.ClickLegendButton(0, "Line", false);
177  yield return new WaitForSeconds(0.2f);
178  chart.ClickLegendButton(0, "Line", true);
179  yield return new WaitForSeconds(0.5f);
180 
181  chart.ClickLegendButton(1, "Bar", false);
182  yield return new WaitForSeconds(0.2f);
183  chart.ClickLegendButton(1, "Bar", true);
184  yield return new WaitForSeconds(0.5f);
185  }
186 
187  IEnumerator ComponentTheme()
188  {
189  chart.title.subText = "Theme 主题:可从全局上配置图表的颜色、字体等效果,支持默认主题切换";
190  yield return new WaitForSeconds(1f);
191  chart.title.subText = "Theme 主题:Light主题";
192  chart.UpdateTheme(Theme.Light);
193  yield return new WaitForSeconds(1f);
194  chart.title.subText = "Theme 主题:Dark主题";
195  chart.UpdateTheme(Theme.Dark);
196  yield return new WaitForSeconds(1f);
197  chart.title.subText = "Theme 主题:Default主题";
198  chart.UpdateTheme(Theme.Default);
199  yield return new WaitForSeconds(1f);
200  }
201 
202  IEnumerator ComponentDataZoom()
203  {
204  chart.title.subText = "DataZoom 区域缩放:可通过拖、拽、缩小、放大来观察细节数据";
205  chart.grid.bottom = 70;
206 
207  chart.dataZooms[0].enable = true;
208  chart.dataZooms[0].supportInside = true;
209  chart.dataZooms[0].supportSlider = true;
210  chart.dataZooms[0].start = 0;
211  chart.dataZooms[0].end = 100;
212 
213  chart.RefreshChart();
214  for (int i = 0; i < 4; i++)
215  {
216  chart.dataZooms[0].supportSlider = !chart.dataZooms[0].supportSlider;
217  chart.RefreshChart();
218  yield return new WaitForSeconds(0.2f);
219  }
220  chart.dataZooms[0].supportSlider = true;
221  chart.RefreshChart();
222  yield return new WaitForSeconds(1f);
223  while (chart.dataZooms[0].start < 40)
224  {
225  chart.dataZooms[0].start += speed * Time.deltaTime * 0.8f;
226  chart.RefreshDataZoom();
227  chart.RefreshChart();
228  yield return null;
229  }
230  while (chart.dataZooms[0].end > 60)
231  {
232  chart.dataZooms[0].end -= speed * Time.deltaTime * 0.8f;
233  chart.RefreshDataZoom();
234  chart.RefreshChart();
235  yield return null;
236  }
237  while (chart.dataZooms[0].start > 0)
238  {
239  chart.dataZooms[0].start -= speed * Time.deltaTime * 0.8f;
240  chart.dataZooms[0].end -= speed * Time.deltaTime * 0.8f;
241  chart.RefreshDataZoom();
242  chart.RefreshChart();
243  yield return null;
244  }
245  while (chart.dataZooms[0].end < 100)
246  {
247  chart.dataZooms[0].start += speed * Time.deltaTime * 0.8f;
248  chart.dataZooms[0].end += speed * Time.deltaTime * 0.8f;
249  chart.RefreshDataZoom();
250  chart.RefreshChart();
251  yield return null;
252  }
253  while (chart.dataZooms[0].start > 0 || chart.dataZooms[0].end < 100)
254  {
255  chart.dataZooms[0].start -= speed * Time.deltaTime * 0.8f;
256  chart.dataZooms[0].end += speed * Time.deltaTime * 0.8f;
257  chart.RefreshDataZoom();
258  chart.RefreshChart();
259  yield return null;
260  }
261  }
262 
263  IEnumerator ComponentVisualMap()
264  {
265  chart.title.subText = "VisualMap 视觉映射:可从全局上配置图表的颜色、字体等效果,支持默认主题切换";
266 
267  chart.visualMap.enable = true;
268  chart.visualMap.show = true;
269  chart.visualMap.orient = Orient.Vertical;
270  chart.visualMap.calculable = true;
271  chart.visualMap.min = 0;
272  chart.visualMap.max = 100;
273  chart.visualMap.range[0] = 0;
274  chart.visualMap.range[1] = 100;
275 
276  var colors = new List<string>{"#313695", "#4575b4", "#74add1", "#abd9e9", "#e0f3f8", "#ffffbf",
277  "#fee090", "#fdae61", "#f46d43", "#d73027", "#a50026"};
278  chart.visualMap.inRange.Clear();
279  foreach (var str in colors)
280  {
281  chart.visualMap.inRange.Add(ChartTheme.GetColor(str));
282  }
283  chart.grid.left = 80;
284  chart.grid.bottom = 100;
285  chart.RefreshChart();
286 
287  yield return new WaitForSeconds(1f);
288  while (chart.visualMap.rangeMin < 40)
289  {
290  chart.visualMap.rangeMin += speed * Time.deltaTime;
291  chart.RefreshChart();
292  yield return null;
293  }
294  while (chart.visualMap.rangeMax > 60)
295  {
296  chart.visualMap.rangeMax -= speed * Time.deltaTime;
297  chart.RefreshChart();
298  yield return null;
299  }
300  while (chart.visualMap.rangeMin > 0 || chart.visualMap.rangeMax < 100)
301  {
302  chart.visualMap.rangeMin -= speed * Time.deltaTime;
303  chart.visualMap.rangeMax += speed * Time.deltaTime;
304  chart.RefreshChart();
305  yield return null;
306  }
307  }
308  }
309 }
XCharts.Orient
Orient
the layout is horizontal or vertical. 垂直还是水平布局方式。
Definition: BaseChart.cs:22
XCharts.CoordinateChart.xAxis0
XAxis? xAxis0
X轴(下)
Definition: CoordinateChart_API.cs:40
XCharts.Theme
Theme
主题
Definition: ChartTheme.cs:21
XCharts.CoordinateChart.RefreshDataZoom
void RefreshDataZoom()
在下一帧刷新DataZoom
Definition: CoordinateChart_API.cs:297
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.yAxis0
YAxis? yAxis0
Y轴(左)
Definition: CoordinateChart_API.cs:48
XCharts.Grid.backgroundColor
Color backgroundColor
Background color of grid, which is transparent by default. 网格背景色,默认透明。
Definition: XGrid.cs:84
XCharts.ChartTheme.GetColor
Color32 GetColor(int index)
Gets the color of the specified index from the palette. 获得调色盘对应系列索引的颜色值。
Definition: ChartTheme.cs:221
XCharts.CoordinateChart.AddXAxisData
void AddXAxisData(string category, int xAxisIndex=0)
Add a category data to xAxis. 添加一个类目数据到指定的x轴。
Definition: CoordinateChart_API.cs:101
XCharts.Grid.bottom
float bottom
Distance between grid component and the bottom side of the container. grid 组件离容器下侧的距离。
Definition: XGrid.cs:75
XCharts.Grid.left
float left
Distance between grid component and the left side of the container. grid 组件离容器左侧的距离。
Definition: XGrid.cs:48
XCharts.Examples.Example00_CheatSheet
Definition: Example00_CheatSheet.cs:15
XCharts.Grid.right
float right
Distance between grid component and the right side of the container. grid 组件离容器右侧的距离。
Definition: XGrid.cs:57
XCharts.LineChart
Definition: LineChart.cs:17
XCharts.Axis.show
bool show
Whether to show axis. 是否显示坐标轴。
Definition: Axis.cs:121
XCharts.Examples
Definition: RewardChart.cs:14
XCharts.ChartTheme
Theme. 主题相关配置。
Definition: ChartTheme.cs:46
XCharts.Grid.top
float top
Distance between grid component and the top side of the container. grid 组件离容器上侧的距离。
Definition: XGrid.cs:66
XCharts.CoordinateChart.grid
Grid? grid
grid component. 网格组件。
Definition: CoordinateChart_API.cs:24
XCharts.ComponentTheme
Definition: ComponentTheme.cs:17