Files
XCharts/Examples/Example80_Polar.cs

55 lines
1.5 KiB
C#
Raw Normal View History

2020-07-01 09:38:00 +08:00
using UnityEngine;
2022-02-19 22:37:57 +08:00
using XCharts.Runtime;
#if INPUT_SYSTEM_ENABLED
using Input = XCharts.Runtime.InputHelper;
#endif
2021-12-24 13:33:09 +08:00
namespace XCharts.Example
2020-07-01 09:38:00 +08:00
{
[DisallowMultipleComponent]
[ExecuteInEditMode]
public class Example80_Polar : MonoBehaviour
{
2021-11-23 13:20:07 +08:00
private BaseChart chart;
2020-07-01 09:38:00 +08:00
private float updateTime;
void Awake()
{
2021-11-23 13:20:07 +08:00
chart = gameObject.GetComponent<BaseChart>();
2020-07-01 09:38:00 +08:00
if (chart == null)
{
2021-11-23 13:20:07 +08:00
chart = gameObject.AddComponent<BaseChart>();
2024-01-21 22:33:45 +08:00
chart.Init();
2020-07-01 09:38:00 +08:00
}
chart.EnsureChartComponent<PolarCoord>();
2020-07-01 09:38:00 +08:00
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
AddData();
}
}
void AddData()
{
chart.RemoveData();
chart.GetChartComponent<Tooltip>().type = Tooltip.Type.Cross;
2021-11-23 13:20:07 +08:00
var angleAxis = chart.GetChartComponent<AngleAxis>();
angleAxis.type = Axis.AxisType.Value;
angleAxis.minMaxType = Axis.AxisMinMaxType.Custom;
angleAxis.min = 0;
angleAxis.max = 360;
angleAxis.startAngle = Random.Range(0, 90);
chart.AddSerie<Line>("line1");
2020-07-01 09:38:00 +08:00
var rate = Random.Range(1, 4);
for (int i = 0; i <= 360; i++)
{
var t = i / 180f * Mathf.PI;
var r = Mathf.Sin(2 * t) * Mathf.Cos(2 * t) * rate;
chart.AddData(0, Mathf.Abs(r), i);
}
}
}
}