Files
XCharts/Examples/Example11_AddSinCurve.cs

61 lines
1.7 KiB
C#
Raw Normal View History

using UnityEngine;
2022-02-19 22:37:57 +08:00
using XCharts.Runtime;
2021-12-24 13:33:09 +08:00
namespace XCharts.Example
{
[DisallowMultipleComponent]
public class Example11_AddSinCurve : MonoBehaviour
{
private float time;
public int angle;
private LineChart chart;
void Awake()
{
chart = gameObject.GetComponent<LineChart>();
2021-01-11 08:54:28 +08:00
if (chart == null)
{
2021-01-11 08:54:28 +08:00
chart = gameObject.AddComponent<LineChart>();
}
chart.EnsureChartComponent<Title>().show = true;
chart.EnsureChartComponent<Title>().text = "Sin Curve";
chart.EnsureChartComponent<Tooltip>().show = true;
chart.EnsureChartComponent<Legend>().show = false;
var xAxis = chart.EnsureChartComponent<XAxis>();
var yAxis = chart.EnsureChartComponent<YAxis>();
2021-11-23 13:20:07 +08:00
xAxis.show = true;
yAxis.show = true;
2021-11-23 13:20:07 +08:00
xAxis.type = Axis.AxisType.Value;
yAxis.type = Axis.AxisType.Value;
xAxis.boundaryGap = false;
xAxis.maxCache = 0;
chart.series[0].maxCache = 0;
chart.RemoveData();
2021-11-23 13:20:07 +08:00
var serie = chart.AddSerie<Line>();
serie.symbol.show = false;
serie.lineType = LineType.Normal;
for (angle = 0; angle < 1080; angle++)
{
float xvalue = Mathf.PI / 180 * angle;
float yvalue = Mathf.Sin(xvalue);
chart.AddData(0, xvalue, yvalue);
}
}
void Update()
{
if (angle > 3000) return;
angle++;
float xvalue = Mathf.PI / 180 * angle;
float yvalue = Mathf.Sin(xvalue);
chart.AddData(0, xvalue, yvalue);
}
}
}