Files
XCharts/Examples/Runtime/Example13_LineSimple.cs

46 lines
1.4 KiB
C#
Raw Normal View History

2021-12-24 13:33:09 +08:00

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]
[ExecuteInEditMode]
public class Example13_LineSimple : MonoBehaviour
{
void Awake()
{
var chart = gameObject.GetComponent<LineChart>();
if (chart == null)
{
chart = gameObject.AddComponent<LineChart>();
2020-09-19 17:56:56 +08:00
chart.SetSize(580, 300);//代码动态添加图表需要设置尺寸或直接操作chart.rectTransform
}
2021-11-23 13:20:07 +08:00
chart.GetChartComponent<Title>().show = true;
chart.GetChartComponent<Title>().text = "Line Simple";
2021-11-23 13:20:07 +08:00
chart.GetChartComponent<Tooltip>().show = true;
chart.GetChartComponent<Legend>().show = false;
2021-11-23 13:20:07 +08:00
var xAxis = chart.GetChartComponent<XAxis>();
var yAxis = chart.GetChartComponent<YAxis>();
xAxis.show = true;
yAxis.show = true;
xAxis.type = Axis.AxisType.Category;
yAxis.type = Axis.AxisType.Value;
2021-11-23 13:20:07 +08:00
xAxis.splitNumber = 10;
xAxis.boundaryGap = true;
chart.RemoveData();
2021-11-23 13:20:07 +08:00
chart.AddSerie<Line>();
chart.AddSerie<Line>();
2021-01-11 08:54:28 +08:00
for (int i = 0; i < 2000; i++)
{
chart.AddXAxisData("x" + i);
chart.AddData(0, Random.Range(10, 20));
chart.AddData(1, Random.Range(10, 20));
}
}
}
}