Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HeatmapChart.cs 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace XCharts.Runtime
  4. {
  5. [AddComponentMenu("XCharts/HeatmapChart", 18)]
  6. [ExecuteInEditMode]
  7. [RequireComponent(typeof(RectTransform))]
  8. [DisallowMultipleComponent]
  9. public class HeatmapChart : BaseChart
  10. {
  11. protected override void DefaultChart()
  12. {
  13. var tooltip = GetChartComponent<Tooltip>();
  14. tooltip.type = Tooltip.Type.None;
  15. tooltip.trigger = Tooltip.Trigger.Axis;
  16. var grid = GetOrAddChartComponent<GridCoord>();
  17. grid.left = 0.12f;
  18. var xAxis = GetOrAddChartComponent<XAxis>();
  19. xAxis.type = Axis.AxisType.Category;
  20. xAxis.boundaryGap = true;
  21. xAxis.splitNumber = 10;
  22. var yAxis = GetOrAddChartComponent<YAxis>();
  23. yAxis.type = Axis.AxisType.Category;
  24. yAxis.boundaryGap = true;
  25. yAxis.splitNumber = 10;
  26. RemoveData();
  27. var heatmapGridWid = 10f;
  28. int xSplitNumber = (int) (grid.context.width / heatmapGridWid);
  29. int ySplitNumber = (int) (grid.context.height / heatmapGridWid);
  30. Heatmap.AddDefaultSerie(this, GenerateDefaultSerieName());
  31. var visualMap = GetOrAddChartComponent<VisualMap>();
  32. visualMap.autoMinMax = true;
  33. visualMap.orient = Orient.Vertical;
  34. visualMap.calculable = true;
  35. visualMap.location.align = Location.Align.BottomLeft;
  36. visualMap.location.bottom = 100;
  37. visualMap.location.left = 30;
  38. var colors = new List<string>
  39. {
  40. "#313695",
  41. "#4575b4",
  42. "#74add1",
  43. "#abd9e9",
  44. "#e0f3f8",
  45. "#ffffbf",
  46. "#fee090",
  47. "#fdae61",
  48. "#f46d43",
  49. "#d73027",
  50. "#a50026"
  51. };
  52. visualMap.AddColors(colors);
  53. for (int i = 0; i < xSplitNumber; i++)
  54. {
  55. xAxis.data.Add((i + 1).ToString());
  56. }
  57. for (int i = 0; i < ySplitNumber; i++)
  58. {
  59. yAxis.data.Add((i + 1).ToString());
  60. }
  61. for (int i = 0; i < xSplitNumber; i++)
  62. {
  63. for (int j = 0; j < ySplitNumber; j++)
  64. {
  65. var value = Random.Range(0, 150);
  66. var list = new List<double> { i, j, value };
  67. AddData(0, list);
  68. }
  69. }
  70. }
  71. }
  72. }