2021-01-11 08:54:28 +08:00
|
|
|
|
/************************************************/
|
|
|
|
|
|
/* */
|
|
|
|
|
|
/* Copyright (c) 2018 - 2021 monitor1394 */
|
|
|
|
|
|
/* https://github.com/monitor1394 */
|
|
|
|
|
|
/* */
|
|
|
|
|
|
/************************************************/
|
2019-10-22 04:09:04 +08:00
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
2020-05-15 06:52:40 +08:00
|
|
|
|
namespace XCharts.Examples
|
2019-10-22 04:09:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
[DisallowMultipleComponent]
|
|
|
|
|
|
[ExecuteInEditMode]
|
2020-05-15 06:52:40 +08:00
|
|
|
|
public class Example60_Heatmap : MonoBehaviour
|
2019-10-22 04:09:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
private HeatmapChart chart;
|
|
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
chart = gameObject.GetComponent<HeatmapChart>();
|
|
|
|
|
|
if (chart == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
chart = gameObject.AddComponent<HeatmapChart>();
|
|
|
|
|
|
}
|
|
|
|
|
|
chart.title.text = "HeatmapChart";
|
|
|
|
|
|
chart.tooltip.type = Tooltip.Type.None;
|
|
|
|
|
|
chart.grid.left = 100;
|
|
|
|
|
|
chart.grid.right = 60;
|
|
|
|
|
|
chart.grid.bottom = 60;
|
|
|
|
|
|
//目前只支持Category
|
2021-01-11 08:54:28 +08:00
|
|
|
|
chart.xAxes[0].type = Axis.AxisType.Category;
|
|
|
|
|
|
chart.yAxes[0].type = Axis.AxisType.Category;
|
2019-10-22 04:09:04 +08:00
|
|
|
|
|
2021-01-11 08:54:28 +08:00
|
|
|
|
chart.xAxes[0].boundaryGap = true;
|
|
|
|
|
|
chart.xAxes[0].boundaryGap = true;
|
2019-10-22 04:09:04 +08:00
|
|
|
|
|
2021-01-11 08:54:28 +08:00
|
|
|
|
chart.xAxes[0].splitNumber = 10;
|
|
|
|
|
|
chart.yAxes[0].splitNumber = 10;
|
2019-10-22 04:09:04 +08:00
|
|
|
|
|
|
|
|
|
|
//清空数据重新添加
|
|
|
|
|
|
chart.RemoveData();
|
|
|
|
|
|
var serie = chart.AddSerie(SerieType.Heatmap, "serie1");
|
|
|
|
|
|
|
|
|
|
|
|
//设置样式
|
|
|
|
|
|
serie.itemStyle.show = true;
|
|
|
|
|
|
serie.itemStyle.borderWidth = 1;
|
|
|
|
|
|
serie.itemStyle.borderColor = Color.clear;
|
|
|
|
|
|
|
|
|
|
|
|
//设置高亮样式
|
|
|
|
|
|
serie.emphasis.show = true;
|
|
|
|
|
|
serie.emphasis.itemStyle.show = true;
|
|
|
|
|
|
serie.emphasis.itemStyle.borderWidth = 1;
|
|
|
|
|
|
serie.emphasis.itemStyle.borderColor = Color.black;
|
|
|
|
|
|
|
|
|
|
|
|
//设置视觉映射组件
|
|
|
|
|
|
chart.visualMap.enable = true;
|
|
|
|
|
|
chart.visualMap.max = 10;
|
|
|
|
|
|
chart.visualMap.range[0] = 0f;
|
|
|
|
|
|
chart.visualMap.range[1] = 10f;
|
|
|
|
|
|
chart.visualMap.orient = Orient.Vertical;
|
|
|
|
|
|
chart.visualMap.calculable = true;
|
|
|
|
|
|
chart.visualMap.location.align = Location.Align.BottomLeft;
|
|
|
|
|
|
chart.visualMap.location.bottom = 100;
|
|
|
|
|
|
chart.visualMap.location.left = 30;
|
|
|
|
|
|
|
|
|
|
|
|
//清空颜色重新添加
|
|
|
|
|
|
chart.visualMap.inRange.Clear();
|
|
|
|
|
|
|
|
|
|
|
|
var heatmapGridWid = 10f;
|
2021-01-11 08:54:28 +08:00
|
|
|
|
int xSplitNumber = (int)(chart.grid.runtimeWidth / heatmapGridWid);
|
|
|
|
|
|
int ySplitNumber = (int)(chart.grid.runtimeHeight / heatmapGridWid);
|
2019-10-22 04:09:04 +08:00
|
|
|
|
var colors = new List<string>{"#313695", "#4575b4", "#74add1", "#abd9e9", "#e0f3f8", "#ffffbf",
|
|
|
|
|
|
"#fee090", "#fdae61", "#f46d43", "#d73027", "#a50026"};
|
|
|
|
|
|
foreach (var str in colors)
|
|
|
|
|
|
{
|
2021-01-11 08:54:28 +08:00
|
|
|
|
chart.visualMap.inRange.Add(ChartTheme.GetColor(str));
|
2019-10-22 04:09:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
//添加xAxis的数据
|
|
|
|
|
|
for (int i = 0; i < xSplitNumber; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
chart.AddXAxisData((i + 1).ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
//添加yAxis的数据
|
|
|
|
|
|
for (int i = 0; i < ySplitNumber; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
chart.AddYAxisData((i + 1).ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
for (int i = 0; i < xSplitNumber; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int j = 0; j < ySplitNumber; j++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var value = 0f;
|
|
|
|
|
|
var rate = Random.Range(0, 101);
|
|
|
|
|
|
if (rate > 70) value = Random.Range(8f, 10f);
|
|
|
|
|
|
else value = Random.Range(1f, 8f);
|
2021-07-08 07:19:31 +08:00
|
|
|
|
var list = new List<double> { i, j, value };
|
2019-10-22 04:09:04 +08:00
|
|
|
|
//至少是一个三位数据:(x,y,value)
|
|
|
|
|
|
chart.AddData(0, list);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|