AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
Example60_Heatmap.cs
1 /************************************************/
2 /* */
3 /* Copyright (c) 2018 - 2021 monitor1394 */
4 /* https://github.com/monitor1394 */
5 /* */
6 /************************************************/
7 
8 using System.Collections.Generic;
9 using UnityEngine;
10 
11 namespace XCharts.Examples
12 {
13  [DisallowMultipleComponent]
14  [ExecuteInEditMode]
15  public class Example60_Heatmap : MonoBehaviour
16  {
17  private HeatmapChart chart;
18 
19  void Awake()
20  {
21  chart = gameObject.GetComponent<HeatmapChart>();
22  if (chart == null)
23  {
24  chart = gameObject.AddComponent<HeatmapChart>();
25  }
26  chart.title.text = "HeatmapChart";
27  chart.tooltip.type = Tooltip.Type.None;
28  chart.grid.left = 100;
29  chart.grid.right = 60;
30  chart.grid.bottom = 60;
31  //目前只支持Category
32  chart.xAxes[0].type = Axis.AxisType.Category;
33  chart.yAxes[0].type = Axis.AxisType.Category;
34 
35  chart.xAxes[0].boundaryGap = true;
36  chart.xAxes[0].boundaryGap = true;
37 
38  chart.xAxes[0].splitNumber = 10;
39  chart.yAxes[0].splitNumber = 10;
40 
41  //清空数据重新添加
42  chart.RemoveData();
43  var serie = chart.AddSerie(SerieType.Heatmap, "serie1");
44 
45  //设置样式
46  serie.itemStyle.show = true;
47  serie.itemStyle.borderWidth = 1;
48  serie.itemStyle.borderColor = Color.clear;
49 
50  //设置高亮样式
51  serie.emphasis.show = true;
52  serie.emphasis.itemStyle.show = true;
53  serie.emphasis.itemStyle.borderWidth = 1;
54  serie.emphasis.itemStyle.borderColor = Color.black;
55 
56  //设置视觉映射组件
57  chart.visualMap.enable = true;
58  chart.visualMap.max = 10;
59  chart.visualMap.range[0] = 0f;
60  chart.visualMap.range[1] = 10f;
61  chart.visualMap.orient = Orient.Vertical;
62  chart.visualMap.calculable = true;
63  chart.visualMap.location.align = Location.Align.BottomLeft;
64  chart.visualMap.location.bottom = 100;
65  chart.visualMap.location.left = 30;
66 
67  //清空颜色重新添加
68  chart.visualMap.inRange.Clear();
69 
70  var heatmapGridWid = 10f;
71  int xSplitNumber = (int)(chart.grid.runtimeWidth / heatmapGridWid);
72  int ySplitNumber = (int)(chart.grid.runtimeHeight / heatmapGridWid);
73  var colors = new List<string>{"#313695", "#4575b4", "#74add1", "#abd9e9", "#e0f3f8", "#ffffbf",
74  "#fee090", "#fdae61", "#f46d43", "#d73027", "#a50026"};
75  foreach (var str in colors)
76  {
77  chart.visualMap.inRange.Add(ChartTheme.GetColor(str));
78  }
79  //添加xAxis的数据
80  for (int i = 0; i < xSplitNumber; i++)
81  {
82  chart.AddXAxisData((i + 1).ToString());
83  }
84  //添加yAxis的数据
85  for (int i = 0; i < ySplitNumber; i++)
86  {
87  chart.AddYAxisData((i + 1).ToString());
88  }
89  for (int i = 0; i < xSplitNumber; i++)
90  {
91  for (int j = 0; j < ySplitNumber; j++)
92  {
93  var value = 0f;
94  var rate = Random.Range(0, 101);
95  if (rate > 70) value = Random.Range(8f, 10f);
96  else value = Random.Range(1f, 8f);
97  var list = new List<double> { i, j, value };
98  //至少是一个三位数据:(x,y,value)
99  chart.AddData(0, list);
100  }
101  }
102  }
103  }
104 }
XCharts.Orient
Orient
the layout is horizontal or vertical. 垂直还是水平布局方式。
Definition: BaseChart.cs:22
XCharts.Tooltip.Type
Type
Indicator type. 指示器类型。
Definition: Tooltip.cs:25
XCharts.Tooltip
Tooltip component. 提示框组件。
Definition: Tooltip.cs:19
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.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.HeatmapChart
Definition: HeatmapChart.cs:17
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.CoordinateChart.AddYAxisData
void AddYAxisData(string category, int yAxisIndex=0)
Add a category data to yAxis. 添加一个类目数据到指定的y轴。
Definition: CoordinateChart_API.cs:163
XCharts.Axis
The axis in rectangular coordinate. 直角坐标系的坐标轴组件。
Definition: Axis.cs:20
XCharts.Grid.left
float left
Distance between grid component and the left side of the container. grid 组件离容器左侧的距离。
Definition: XGrid.cs:48
XCharts.Grid.right
float right
Distance between grid component and the right side of the container. grid 组件离容器右侧的距离。
Definition: XGrid.cs:57
XCharts.CoordinateChart.yAxes
List< YAxis > yAxes
the y Axes, yAxes[0] is the first y axis, yAxes[1] is the second y axis. 两个y轴。
Definition: CoordinateChart_API.cs:35
XCharts.Examples.Example60_Heatmap
Definition: Example60_Heatmap.cs:15
XCharts.Examples
Definition: RewardChart.cs:14
XCharts.ChartTheme
Theme. 主题相关配置。
Definition: ChartTheme.cs:46
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.Axis.AxisType
AxisType
the type of axis. 坐标轴类型。
Definition: Axis.cs:26
XCharts.CoordinateChart.grid
Grid? grid
grid component. 网格组件。
Definition: CoordinateChart_API.cs:24