Files
XCharts/Examples/Runtime/Example_Test.cs

58 lines
1.7 KiB
C#
Raw Normal View History

2021-01-11 08:54:28 +08:00
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts.Examples
{
[DisallowMultipleComponent]
[ExecuteInEditMode]
public class Example_Test : MonoBehaviour
{
2021-01-11 08:54:28 +08:00
LineChart chart;
void Awake()
{
2021-01-11 08:54:28 +08:00
chart = gameObject.GetComponent<LineChart>();
var btnTrans = transform.parent.Find("Button");
if (btnTrans)
{
btnTrans.gameObject.GetComponent<Button>().onClick.AddListener(OnTestBtn);
}
}
2019-11-30 21:24:04 +08:00
void Update()
{
2020-03-11 22:04:40 +08:00
if (Input.GetKeyDown(KeyCode.Space))
{
2021-01-11 08:54:28 +08:00
//AddData();
OnTestBtn();
2020-03-11 22:04:40 +08:00
}
}
void OnTestBtn()
{
2021-01-11 08:54:28 +08:00
int index = Random.Range(0, chart.series.Count);
var serie = chart.series.GetSerie(index);
chart.UpdateData(index, Random.Range(0, serie.dataCount), Random.Range(50, 100));
2020-03-11 22:04:40 +08:00
}
void AddData()
{
chart.ClearData();
int count = Random.Range(5, 100);
2020-03-11 22:04:40 +08:00
for (int i = 0; i < count; i++)
{
(chart as CoordinateChart).AddXAxisData("x" + i);
if (Random.Range(1, 3) == 2)
chart.AddData(0, Random.Range(-110, 200));
2020-03-11 22:04:40 +08:00
else
chart.AddData(0, Random.Range(-100, 100));
2020-03-11 22:04:40 +08:00
}
}
}
}