AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
Example30_PieChart.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 using UnityEngine.EventSystems;
11 
12 namespace XCharts.Examples
13 {
14  [DisallowMultipleComponent]
15  public class Example30_PieChart : MonoBehaviour
16  {
17  private PieChart chart;
18  private Serie serie, serie1;
19  private float m_RadiusSpeed = 100f;
20  private float m_CenterSpeed = 1f;
21 
22  void Awake()
23  {
24  LoopDemo();
25  }
26 
27  private void OnEnable()
28  {
29  LoopDemo();
30  }
31 
32  void LoopDemo()
33  {
34  StopAllCoroutines();
35  StartCoroutine(PieDemo());
36  }
37 
38  IEnumerator PieDemo()
39  {
40  StartCoroutine(PieAdd());
41  yield return new WaitForSeconds(2);
42  StartCoroutine(PieShowLabel());
43  yield return new WaitForSeconds(4);
44  StartCoroutine(Doughnut());
45  yield return new WaitForSeconds(3);
46  StartCoroutine(DoublePie());
47  yield return new WaitForSeconds(2);
48  StartCoroutine(RosePie());
49  yield return new WaitForSeconds(5);
50  LoopDemo();
51  }
52 
53  IEnumerator PieAdd()
54  {
55  chart = gameObject.GetComponent<PieChart>();
56  if (chart == null) chart = gameObject.AddComponent<PieChart>();
57  chart.title.text = "PieChart - 饼图";
58  chart.title.subText = "基础饼图";
59 
60  chart.legend.show = true;
61  chart.legend.location.align = Location.Align.TopLeft;
62  chart.legend.location.top = 60;
63  chart.legend.location.left = 2;
64  chart.legend.itemWidth = 70;
65  chart.legend.itemHeight = 20;
66  chart.legend.orient = Orient.Vertical;
67 
68  chart.RemoveData();
69  serie = chart.AddSerie(SerieType.Pie, "访问来源");
70  serie.radius[0] = 0;
71  serie.radius[1] = 110;
72  serie.center[0] = 0.5f;
73  serie.center[1] = 0.4f;
74  chart.AddData(0, 335, "直接访问");
75  chart.AddData(0, 310, "邮件营销");
76  chart.AddData(0, 243, "联盟广告");
77  chart.AddData(0, 135, "视频广告");
78  chart.AddData(0, 1548, "搜索引擎");
79  chart.RefreshLabel();
80 
81  chart.onPointerClickPie = delegate(PointerEventData e, int serieIndex, int dataIndex){
82 
83  };
84  yield return new WaitForSeconds(1);
85  }
86 
87  IEnumerator PieShowLabel()
88  {
89  chart.title.subText = "显示文本标签";
90 
91  serie.label.show = true;
92  chart.RefreshChart();
93  yield return new WaitForSeconds(1);
94  serie.label.lineType = SerieLabel.LineType.Curves;
95  chart.RefreshChart();
96 
97  yield return new WaitForSeconds(1);
98  serie.label.lineType = SerieLabel.LineType.HorizontalLine;
99  chart.RefreshChart();
100 
101  yield return new WaitForSeconds(1);
102  serie.label.lineType = SerieLabel.LineType.BrokenLine;
103  chart.RefreshChart();
104 
105  yield return new WaitForSeconds(1);
106  serie.label.show = false;
107  chart.RefreshChart();
108  }
109 
110  IEnumerator Doughnut()
111  {
112  chart.title.subText = "圆环图";
113  serie.radius[0] = 2f;
114  while (serie.radius[0] < serie.radius[1] * 0.7f)
115  {
116  serie.radius[0] += m_RadiusSpeed * Time.deltaTime;
117  chart.RefreshChart();
118  yield return null;
119  }
120  serie.pieSpace = 1f;
121  chart.RefreshChart();
122  yield return new WaitForSeconds(1);
123 
124  serie.data[0].selected = true;
125  chart.RefreshChart();
126  yield return new WaitForSeconds(1);
127 
128  serie.pieSpace = 0f;
129  serie.data[0].selected = false;
130  chart.RefreshChart();
131  yield return new WaitForSeconds(1);
132  }
133 
134  IEnumerator DoublePie()
135  {
136  chart.title.subText = "多图组合";
137 
138  serie1 = chart.AddSerie(SerieType.Pie, "访问来源2");
139  chart.AddData(1, 335, "直达");
140  chart.AddData(1, 679, "营销广告");
141  chart.AddData(1, 1548, "搜索引擎");
142  serie1.radius[0] = 0;
143  serie1.radius[1] = 2f;
144  serie1.center[0] = 0.5f;
145  serie1.center[1] = 0.4f;
146  chart.RefreshChart();
147  while (serie1.radius[1] < serie.radius[0] * 0.75f)
148  {
149  serie1.radius[1] += m_RadiusSpeed * Time.deltaTime;
150  chart.RefreshChart();
151  yield return null;
152  }
153 
154  serie1.label.show = true;
155  serie1.label.position = SerieLabel.Position.Inside;
156  serie1.label.textStyle.color = Color.white;
157  serie1.label.textStyle.fontSize = 14;
158  serie1.label.border = false;
159 
160  chart.RefreshLabel();
161  chart.RefreshChart();
162  yield return new WaitForSeconds(1);
163  }
164 
165  IEnumerator RosePie()
166  {
167  chart.title.subText = "玫瑰图";
168  chart.legend.show = false;
169  serie1.ClearData();
170  serie.ClearData();
171  serie1.radius = serie.radius = new float[2] { 0, 80 };
172  serie1.label.position = SerieLabel.Position.Outside;
173  serie1.label.lineType = SerieLabel.LineType.Curves;
174  serie1.label.textStyle.color = Color.clear;
175  for (int i = 0; i < 2; i++)
176  {
177  chart.AddData(i, 10, "rose1");
178  chart.AddData(i, 5, "rose2");
179  chart.AddData(i, 15, "rose3");
180  chart.AddData(i, 25, "rose4");
181  chart.AddData(i, 20, "rose5");
182  chart.AddData(i, 35, "rose6");
183  chart.AddData(i, 30, "rose7");
184  chart.AddData(i, 40, "rose8");
185  }
186 
187  while (serie.center[0] > 0.25f || serie1.center[0] < 0.7f)
188  {
189  if (serie.center[0] > 0.25f) serie.center[0] -= m_CenterSpeed * Time.deltaTime;
190  if (serie1.center[0] < 0.7f) serie1.center[0] += m_CenterSpeed * Time.deltaTime;
191  chart.RefreshChart();
192  yield return null;
193  }
194  yield return new WaitForSeconds(1);
195  while (serie.radius[0] > 3f)
196  {
197  serie.radius[0] -= m_RadiusSpeed * Time.deltaTime;
198  serie1.radius[0] -= m_RadiusSpeed * Time.deltaTime;
199  chart.RefreshChart();
200  yield return null;
201  }
202 
203  serie.radius[0] = 0;
204  serie1.radius[0] = 0;
205  serie.pieRoseType = RoseType.Area;
206  serie1.pieRoseType = RoseType.Radius;
207  chart.RefreshChart();
208  yield return new WaitForSeconds(1);
209  }
210  }
211 }
XCharts.Orient
Orient
the layout is horizontal or vertical. 垂直还是水平布局方式。
Definition: BaseChart.cs:22
XCharts.SerieLabel.position
Position position
The position of label. 标签的位置。
Definition: SerieLabel.cs:158
XCharts.Title.text
string text
The main title text, supporting for newlines. 主标题文本,支持使用 换行。
Definition: Title.cs:38
XCharts.SerieLabel.textStyle
TextStyle textStyle
the sytle of text. 文本样式。
Definition: SerieLabel.cs:351
XCharts.RoseType
RoseType
Whether to show as Nightingale chart, which distinguishs data through radius. 是否展示成南丁格尔图,通过半径区分数据大小。
Definition: Serie.cs:77
XCharts.BaseChart.AddData
virtual SerieData AddData(string serieName, double data, string dataName=null)
Add a data to serie. If serieName doesn't exist in legend,will be add to legend. 添加一个数据到指定的系列中。
Definition: BaseChart_API.cs:237
XCharts.Location.Align
Align
对齐方式
Definition: Location.cs:26
XCharts.Location
Location type. Quick to set the general location. 位置类型。通过Align快速设置大体位置,再通过left,right,top,bottom微调具体位置...
Definition: Location.cs:21
XCharts.SerieType
SerieType
the type of serie. 系列类型。
Definition: Serie.cs:19
XCharts.BaseChart.RefreshChart
void RefreshChart()
Redraw chart in next frame. 在下一帧刷新图表。
Definition: BaseChart_API.cs:140
XCharts.Serie.pieRoseType
RoseType pieRoseType
Whether to show as Nightingale chart. 是否展示成南丁格尔图,通过半径区分数据大小。
Definition: Serie.cs:633
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.Legend.show
bool show
Whether to show legend component. 是否显示图例组件。
Definition: Legend.cs:95
XCharts.SerieLabel.lineType
LineType lineType
the type of visual guide line. 视觉引导线类型。
Definition: SerieLabel.cs:249
XCharts.Legend.location
Location location
The location of legend. 图例显示的位置。 [default:Location.defaultTop]
Definition: Legend.cs:135
XCharts.PieChart
Definition: PieChart.cs:16
XCharts.SerieLabel.show
bool show
Whether the label is showed. 是否显示文本标签。
Definition: SerieLabel.cs:149
XCharts.Examples.Example30_PieChart
Definition: Example30_PieChart.cs:15
XCharts.SerieLabel.LineType
LineType
标签视觉引导线类型
Definition: SerieLabel.cs:81
XCharts.Location.top
float top
Distance between component and the left side of the container. 离容器上侧的距离。
Definition: Location.cs:84
XCharts.Title.subText
string subText
Subtitle text, supporting for for newlines. 副标题文本,支持使用 换行。
Definition: Title.cs:53
XCharts.Legend.orient
Orient orient
Specify whether the layout of legend component is horizontal or vertical. 布局方式是横还是竖。 [default:Orient....
Definition: Legend.cs:125
XCharts.Serie.data
List< SerieData > data
系列中的数据内容数组。SerieData可以设置1到n维数据。
Definition: Serie.cs:1086
XCharts.Serie
系列。每个系列通过 type 决定自己的图表类型。
Definition: Serie.cs:261
XCharts.Location.left
float left
Distance between component and the left side of the container. 离容器左侧的距离。
Definition: Location.cs:66
XCharts.SerieLabel
Text label of chart, to explain some data information about graphic item like value,...
Definition: SerieLabel.cs:18
XCharts.Examples
Definition: RewardChart.cs:14
XCharts.Legend.itemHeight
float itemHeight
Image height of legend symbol. 图例标记的图形高度。 [default:12f]
Definition: Legend.cs:155
XCharts.TextStyle.color
Color color
the color of text. 文本的颜色。 [default: Color.clear]
Definition: TextStyle.cs:68
XCharts.BaseChart.AddSerie
virtual Serie AddSerie(SerieType type, string serieName=null, bool show=true, bool addToHead=false)
Add a serie to serie list. 添加一个系列到系列列表中。
Definition: BaseChart_API.cs:199
XCharts.BaseChart.RefreshLabel
void RefreshLabel()
刷新文本标签Label,重新初始化,当有改动Label参数时手动调用改接口
Definition: BaseChart_API.cs:607
XCharts.BaseChart.legend
Legend? legend
The legend setting of chart. 图例组件
Definition: BaseChart_API.cs:55
XCharts.Serie.ClearData
void ClearData()
清空所有数据
Definition: Serie.cs:1364
XCharts.Serie.center
float[] center
the center of chart. 中心点。
Definition: Serie.cs:656
XCharts.BaseChart.onPointerClickPie
Action< PointerEventData, int, int > onPointerClickPie
the callback function of click pie area. 点击饼图区域回调。参数:PointerEventData,SerieIndex,SerieDataIndex
Definition: BaseChart_API.cs:134
XCharts.BaseChart.title
Title? title
The title setting of chart. 标题组件
Definition: BaseChart_API.cs:49
XCharts.Location.align
Align align
对齐方式。
Definition: Location.cs:57
XCharts.Legend.itemWidth
float itemWidth
Image width of legend symbol. 图例标记的图形宽度。 [default:24f]
Definition: Legend.cs:145
XCharts.TextStyle.fontSize
int fontSize
font size. 文本字体大小。 [default: 18]
Definition: TextStyle.cs:98
XCharts.SerieLabel.Position
Position
The position of label. 标签的位置。
Definition: SerieLabel.cs:24
XCharts.Serie.pieSpace
float pieSpace
the space of pie chart item. 饼图项间的空隙留白。
Definition: Serie.cs:642
XCharts.Serie.radius
float[] radius
the radius of chart. 半径。radius[0]表示内径,radius[1]表示外径。
Definition: Serie.cs:665
XCharts.BaseChart.RemoveData
virtual void RemoveData()
Remove all data from series and legend. The series list is also cleared. 清除所有系列和图例数据,系列的列表也会被清除。
Definition: BaseChart_API.cs:166