Files
XCharts/Examples/Example_AddChart.cs

69 lines
1.7 KiB
C#
Raw Normal View History

2022-03-20 18:52:50 +08:00
using UnityEngine;
using XCharts.Runtime;
#if INPUT_SYSTEM_ENABLED
using Input = XCharts.Runtime.InputHelper;
#endif
2022-03-20 18:52:50 +08:00
namespace XCharts.Example
{
[DisallowMultipleComponent]
//[ExecuteInEditMode]
public class Example_AddChart : MonoBehaviour
{
BaseChart chart;
void Awake()
{
//AddChart();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
AddChart();
}
}
void AddChart()
{
chart = gameObject.GetComponent<BaseChart>();
if (chart == null)
{
chart = gameObject.AddComponent<LineChart>();
chart.Init();
chart.SetSize(1200, 600);
}
var title = chart.EnsureChartComponent<Title>();
2022-03-20 18:52:50 +08:00
title.text = "Simple LineChart";
title.subText = "normal line";
var tooltip = chart.EnsureChartComponent<Tooltip>();
2022-03-20 18:52:50 +08:00
tooltip.show = true;
var legend = chart.EnsureChartComponent<Legend>();
2022-03-20 18:52:50 +08:00
legend.show = false;
var xAxis = chart.EnsureChartComponent<XAxis>();
2022-03-20 18:52:50 +08:00
xAxis.splitNumber = 10;
xAxis.boundaryGap = true;
xAxis.type = Axis.AxisType.Category;
var yAxis = chart.EnsureChartComponent<YAxis>();
2022-03-20 18:52:50 +08:00
yAxis.type = Axis.AxisType.Value;
chart.RemoveData();
chart.AddSerie<Line>("line");
for (int i = 0; i < 5; i++)
{
chart.AddXAxisData("x" + i);
chart.AddData(0, Random.Range(10, 20));
}
}
void ModifyComponent()
{
}
}
}