Files
XCharts/Examples/Runtime/Example80_Polar.cs

58 lines
1.6 KiB
C#
Raw Normal View History

2020-07-01 09:38:00 +08:00
using System.Runtime.InteropServices;
2021-01-11 08:54:28 +08:00
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
2020-07-01 09:38:00 +08:00
using UnityEngine;
namespace XCharts.Examples
{
[DisallowMultipleComponent]
[ExecuteInEditMode]
public class Example80_Polar : MonoBehaviour
{
private PolarChart chart;
private float updateTime;
void Awake()
{
chart = gameObject.GetComponent<PolarChart>();
if (chart == null)
{
chart = gameObject.AddComponent<PolarChart>();
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
AddData();
}
}
void AddData()
{
chart.RemoveData();
2020-07-02 09:44:25 +08:00
chart.tooltip.type = Tooltip.Type.Corss;
2020-07-01 09:38:00 +08:00
chart.angleAxis.type = Axis.AxisType.Value;
chart.angleAxis.minMaxType = Axis.AxisMinMaxType.Custom;
chart.angleAxis.min = 0;
chart.angleAxis.max = 360;
2020-07-02 09:44:25 +08:00
chart.angleAxis.startAngle = Random.Range(0, 90);
2020-07-01 09:38:00 +08:00
chart.AddSerie(SerieType.Line, "line1");
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);
}
}
}
}