AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
Example10_LineChart.cs
1 /************************************************/
2 /* */
3 /* Copyright (c) 2018 - 2021 monitor1394 */
4 /* https://github.com/monitor1394 */
5 /* */
6 /************************************************/
7 
8 using System.Collections;
9 using UnityEngine;
10 
11 namespace XCharts.Examples
12 {
13  [DisallowMultipleComponent]
14  public class Example10_LineChart : MonoBehaviour
15  {
16  private LineChart chart;
17  private Serie serie;
18  private int m_DataNum = 8;
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(PieDemo());
34  }
35 
36  IEnumerator PieDemo()
37  {
38  StartCoroutine(AddSimpleLine());
39  yield return new WaitForSeconds(2);
40  StartCoroutine(ChangeLineType());
41  yield return new WaitForSeconds(8);
42  StartCoroutine(LineAreaStyleSettings());
43  yield return new WaitForSeconds(5);
44  StartCoroutine(LineArrowSettings());
45  yield return new WaitForSeconds(2);
46  StartCoroutine(LineSymbolSettings());
47  yield return new WaitForSeconds(7);
48  StartCoroutine(LineLabelSettings());
49  yield return new WaitForSeconds(3);
50  StartCoroutine(LineMutilSerie());
51  yield return new WaitForSeconds(5);
52  LoopDemo();
53  }
54 
55  IEnumerator AddSimpleLine()
56  {
57  chart = gameObject.GetComponent<LineChart>();
58  if (chart == null) chart = gameObject.AddComponent<LineChart>();
59  chart.title.text = "LineChart - 折线图";
60  chart.title.subText = "普通折线图";
61 
62  chart.yAxis0.minMaxType = Axis.AxisMinMaxType.Custom;
63  chart.yAxis0.min = 0;
64  chart.yAxis0.max = 100;
65 
66  chart.RemoveData();
67  serie = chart.AddSerie(SerieType.Line, "Line");
68 
69  for (int i = 0; i < m_DataNum; i++)
70  {
71  chart.AddXAxisData("x" + (i + 1));
72  chart.AddData(0, UnityEngine.Random.Range(30, 90));
73  }
74  yield return new WaitForSeconds(1);
75  }
76 
77  IEnumerator ChangeLineType()
78  {
79  chart.title.subText = "LineTyle - 曲线图";
80  serie.lineType = LineType.Smooth;
81  chart.RefreshChart();
82  yield return new WaitForSeconds(1);
83 
84  chart.title.subText = "LineTyle - 阶梯线图";
85  serie.lineType = LineType.StepStart;
86  chart.RefreshChart();
87  yield return new WaitForSeconds(1);
88 
89  serie.lineType = LineType.StepMiddle;
90  chart.RefreshChart();
91  yield return new WaitForSeconds(1);
92 
93  serie.lineType = LineType.StepEnd;
94  chart.RefreshChart();
95  yield return new WaitForSeconds(1);
96 
97  chart.title.subText = "LineTyle - 虚线";
98  serie.lineType = LineType.Dash;
99  chart.RefreshChart();
100  yield return new WaitForSeconds(1);
101 
102  chart.title.subText = "LineTyle - 点线";
103  serie.lineType = LineType.Dot;
104  chart.RefreshChart();
105  yield return new WaitForSeconds(1);
106 
107  chart.title.subText = "LineTyle - 点划线";
108  serie.lineType = LineType.DashDot;
109  chart.RefreshChart();
110  yield return new WaitForSeconds(1);
111 
112  chart.title.subText = "LineTyle - 双点划线";
113  serie.lineType = LineType.DashDotDot;
114  chart.RefreshChart();
115 
116  serie.lineType = LineType.Normal;
117  chart.RefreshChart();
118  }
119 
120  IEnumerator LineAreaStyleSettings()
121  {
122  chart.title.subText = "AreaStyle 面积图";
123 
124  serie.areaStyle.show = true;
125  chart.RefreshChart();
126  yield return new WaitForSeconds(1f);
127 
128  chart.title.subText = "AreaStyle 面积图";
129  serie.lineType = LineType.Smooth;
130  serie.areaStyle.show = true;
131  chart.RefreshChart();
132  yield return new WaitForSeconds(1f);
133 
134  chart.title.subText = "AreaStyle 面积图 - 调整透明度";
135  while (serie.areaStyle.opacity > 0.4)
136  {
137  serie.areaStyle.opacity -= 0.6f * Time.deltaTime;
138  chart.RefreshChart();
139  yield return null;
140  }
141  yield return new WaitForSeconds(1);
142 
143  chart.title.subText = "AreaStyle 面积图 - 渐变";
144  serie.areaStyle.toColor = Color.white;
145  chart.RefreshChart();
146  yield return new WaitForSeconds(1);
147  }
148 
149  IEnumerator LineArrowSettings()
150  {
151  chart.title.subText = "LineArrow 头部箭头";
152  serie.lineArrow.show = true;
153  serie.lineArrow.position = LineArrow.Position.Start;
154  chart.RefreshChart();
155  yield return new WaitForSeconds(1);
156 
157  chart.title.subText = "LineArrow 尾部箭头";
158  serie.lineArrow.position = LineArrow.Position.End;
159  chart.RefreshChart();
160  yield return new WaitForSeconds(1);
161  serie.lineArrow.show = false;
162  }
163 
168  IEnumerator LineSymbolSettings()
169  {
170  chart.title.subText = "SerieSymbol 图形标记";
171  while (serie.symbol.size < 5)
172  {
173  serie.symbol.size += 2.5f * Time.deltaTime;
174  chart.RefreshChart();
175  yield return null;
176  }
177  chart.title.subText = "SerieSymbol 图形标记 - 空心圆";
178  yield return new WaitForSeconds(1);
179 
180  chart.title.subText = "SerieSymbol 图形标记 - 实心圆";
181  serie.symbol.type = SerieSymbolType.Circle;
182  chart.RefreshChart();
183  yield return new WaitForSeconds(1);
184 
185  chart.title.subText = "SerieSymbol 图形标记 - 三角形";
186  serie.symbol.type = SerieSymbolType.Triangle;
187  chart.RefreshChart();
188  yield return new WaitForSeconds(1);
189 
190  chart.title.subText = "SerieSymbol 图形标记 - 正方形";
191  serie.symbol.type = SerieSymbolType.Rect;
192  chart.RefreshChart();
193  yield return new WaitForSeconds(1);
194 
195  chart.title.subText = "SerieSymbol 图形标记 - 菱形";
196  serie.symbol.type = SerieSymbolType.Diamond;
197  chart.RefreshChart();
198  yield return new WaitForSeconds(1);
199 
200  chart.title.subText = "SerieSymbol 图形标记";
201  serie.symbol.type = SerieSymbolType.EmptyCircle;
202  chart.RefreshChart();
203  yield return new WaitForSeconds(1);
204  }
205 
210  IEnumerator LineLabelSettings()
211  {
212  chart.title.subText = "SerieLabel 文本标签";
213  serie.label.show = true;
214  serie.label.border = false;
215  chart.RefreshChart();
216  while (serie.label.offset[1] < 20)
217  {
218  serie.label.offset = new Vector3(serie.label.offset.x, serie.label.offset.y + 20f * Time.deltaTime);
219  chart.RefreshChart();
220  yield return null;
221  }
222  yield return new WaitForSeconds(1);
223 
224  serie.label.border = true;
225  chart.RefreshChart();
226  yield return new WaitForSeconds(1);
227 
228  serie.label.textStyle.color = Color.white;
229  serie.label.textStyle.backgroundColor = Color.grey;
230  chart.RefreshLabel();
231  chart.RefreshChart();
232  yield return new WaitForSeconds(1);
233 
234  serie.label.show = false;
235  chart.RefreshChart();
236  }
237 
242  IEnumerator LineMutilSerie()
243  {
244  chart.title.subText = "多系列";
245  var serie2 = chart.AddSerie(SerieType.Line, "Line2");
246  serie2.lineType = LineType.Normal;
247  for (int i = 0; i < m_DataNum; i++)
248  {
249  chart.AddData(1, UnityEngine.Random.Range(30, 90));
250  }
251  yield return new WaitForSeconds(1);
252 
253  var serie3 = chart.AddSerie(SerieType.Line, "Line3");
254  serie3.lineType = LineType.Normal;
255  for (int i = 0; i < m_DataNum; i++)
256  {
257  chart.AddData(2, UnityEngine.Random.Range(30, 90));
258  }
259  yield return new WaitForSeconds(1);
260 
261  chart.yAxis0.minMaxType = Axis.AxisMinMaxType.Default;
262  chart.title.subText = "多系列 - 堆叠";
263  serie.stack = "samename";
264  serie2.stack = "samename";
265  serie3.stack = "samename";
266  chart.RefreshChart();
267  yield return new WaitForSeconds(1);
268  }
269  }
270 }
XCharts.SerieLabel.textStyle
TextStyle textStyle
the sytle of text. 文本样式。
Definition: SerieLabel.cs:351
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.Axis.min
float min
The minimun value of axis.Valid when minMaxType is Custom 设定的坐标轴刻度最小值,当minMaxType为Custom时有效。
Definition: Axis.cs:184
XCharts.CoordinateChart.yAxis0
YAxis? yAxis0
Y轴(左)
Definition: CoordinateChart_API.cs:48
XCharts.TextStyle.backgroundColor
Color backgroundColor
the color of text. 文本的背景颜色。 [default: Color.clear]
Definition: TextStyle.cs:78
XCharts.LineArrow.Position
Position
Definition: LineArrow.cs:18
XCharts.LineType
LineType
the type of line chart. 折线图样式类型
Definition: Serie.cs:99
XCharts.Serie.lineArrow
LineArrow lineArrow
The arrow of line. 折线图的箭头。
Definition: Serie.cs:839
XCharts.CoordinateChart.AddXAxisData
void AddXAxisData(string category, int xAxisIndex=0)
Add a category data to xAxis. 添加一个类目数据到指定的x轴。
Definition: CoordinateChart_API.cs:101
XCharts.LineArrow
Definition: LineArrow.cs:16
XCharts.Serie.label
SerieLabel label
Text label of graphic element,to explain some data information about graphic item like value,...
Definition: Serie.cs:821
XCharts.SerieLabel.border
bool border
Whether to show border. 是否显示边框。
Definition: SerieLabel.cs:303
XCharts.Axis
The axis in rectangular coordinate. 直角坐标系的坐标轴组件。
Definition: Axis.cs:20
XCharts.AreaStyle.show
bool show
Set this to false to prevent the areafrom showing. 是否显示区域填充。
Definition: AreaStyle.cs:56
XCharts.Serie.lineType
LineType lineType
The type of line chart. 折线图样式类型。
Definition: Serie.cs:510
XCharts.AreaStyle.opacity
float opacity
Opacity of the component. Supports value from 0 to 1, and the component will not be drawn when set to...
Definition: AreaStyle.cs:92
XCharts.SerieLabel.show
bool show
Whether the label is showed. 是否显示文本标签。
Definition: SerieLabel.cs:149
XCharts.Axis.max
float max
The maximum value of axis.Valid when minMaxType is Custom 设定的坐标轴刻度最大值,当minMaxType为Custom时有效。
Definition: Axis.cs:193
XCharts.SerieLabel.offset
Vector3 offset
offset to the host graphic element. 距离图形元素的偏移
Definition: SerieLabel.cs:185
XCharts.LineChart
Definition: LineChart.cs:17
XCharts.Serie
系列。每个系列通过 type 决定自己的图表类型。
Definition: Serie.cs:261
XCharts.Examples
Definition: RewardChart.cs:14
XCharts.SerieSymbolType
SerieSymbolType
the type of symbol. 标记图形的类型。
Definition: SerieSymbol.cs:18
XCharts.SerieSymbol.type
SerieSymbolType type
the type of symbol. 标记类型。
Definition: SerieSymbol.cs:152
XCharts.TextStyle.color
Color color
the color of text. 文本的颜色。 [default: Color.clear]
Definition: TextStyle.cs:68
XCharts.Examples.Example10_LineChart
Definition: Example10_LineChart.cs:14
XCharts.Axis.minMaxType
AxisMinMaxType minMaxType
the type of axis minmax. 坐标轴刻度最大最小值显示类型。
Definition: Axis.cs:139
XCharts.AreaStyle.toColor
Color32 toColor
Gradient color, start color to toColor. 渐变色的终点颜色。
Definition: AreaStyle.cs:83
XCharts.LineArrow.show
bool show
Whether to show the arrow. 是否显示箭头。
Definition: LineArrow.cs:45
XCharts.Serie.areaStyle
AreaStyle areaStyle
The style of area. 区域填充样式。
Definition: Serie.cs:492
XCharts.SerieSymbol.size
float size
the size of symbol. 标记的大小。
Definition: SerieSymbol.cs:170
XCharts.LineArrow.position
Position position
The position of arrow. 箭头位置。
Definition: LineArrow.cs:54
XCharts.Serie.symbol
SerieSymbol symbol
the symbol of serie data item. 标记的图形。
Definition: Serie.cs:501
XCharts.Serie.stack
string stack
If stack the value. On the same category axis, the series with the same stack name would be put on to...
Definition: Serie.cs:409
XCharts.Axis.AxisMinMaxType
AxisMinMaxType
the type of axis min and max value. 坐标轴最大最小刻度显示类型。
Definition: Axis.cs:54