This commit is contained in:
monitor1394
2022-03-20 18:52:50 +08:00
parent 4e24ba7922
commit c510831f59
64 changed files with 562 additions and 159 deletions

View File

@@ -14,16 +14,17 @@ namespace XCharts.Example
if (chart == null)
{
chart = gameObject.AddComponent<LineChart>();
chart.SetSize(580, 300);//代码动态添加图表需要设置尺寸或直接操作chart.rectTransform
chart.Init();
chart.SetSize(580, 300);
}
chart.GetChartComponent<Title>().show = true;
chart.GetChartComponent<Title>().text = "Line Simple";
chart.GetOrAddChartComponent<Title>().show = true;
chart.GetOrAddChartComponent<Title>().text = "Line Simple";
chart.GetChartComponent<Tooltip>().show = true;
chart.GetChartComponent<Legend>().show = false;
chart.GetOrAddChartComponent<Tooltip>().show = true;
chart.GetOrAddChartComponent<Legend>().show = false;
var xAxis = chart.GetChartComponent<XAxis>();
var yAxis = chart.GetChartComponent<YAxis>();
var xAxis = chart.GetOrAddChartComponent<XAxis>();
var yAxis = chart.GetOrAddChartComponent<YAxis>();
xAxis.show = true;
yAxis.show = true;
xAxis.type = Axis.AxisType.Category;
@@ -35,7 +36,7 @@ namespace XCharts.Example
chart.RemoveData();
chart.AddSerie<Line>();
chart.AddSerie<Line>();
for (int i = 0; i < 2000; i++)
for (int i = 0; i < 200; i++)
{
chart.AddXAxisData("x" + i);
chart.AddData(0, Random.Range(10, 20));

View File

@@ -0,0 +1,67 @@

using UnityEngine;
using XCharts.Runtime;
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.GetOrAddChartComponent<Title>();
title.text = "Simple LineChart";
title.subText = "normal line";
var tooltip = chart.GetOrAddChartComponent<Tooltip>();
tooltip.show = true;
var legend = chart.GetOrAddChartComponent<Legend>();
legend.show = false;
var xAxis = chart.GetOrAddChartComponent<XAxis>();
xAxis.splitNumber = 10;
xAxis.boundaryGap = true;
xAxis.type = Axis.AxisType.Category;
var yAxis = chart.GetOrAddChartComponent<YAxis>();
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()
{
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8e5c24ed461624b8d924dfb1285e0a95
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,37 @@

using UnityEngine;
using XCharts.Runtime;
namespace XCharts.Example
{
[DisallowMultipleComponent]
//[ExecuteInEditMode]
public class Example_Component : MonoBehaviour
{
BaseChart chart;
void Awake()
{
chart = gameObject.GetComponent<BaseChart>();
}
void ModifyComponent()
{
var title = chart.GetOrAddChartComponent<Title>();
title.text = "Simple LineChart";
title.subText = "normal line";
var serie1 = chart.AddSerie<Line>();
//var serie2 = chart.GetSerie<Line>();
serie1.AddExtraComponent<AreaStyle>();
var label = serie1.AddExtraComponent<LabelStyle>();
label.offset = new Vector3(0, 20, 0);
var serieData = chart.AddData(0, 20);
//var serieData = serie1.GetSerieData(0);
serieData.radius = 10;
var itemStyle = serieData.GetOrAddComponent<ItemStyle>();
itemStyle.color = Color.blue;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2e9941e7d67e44b18899e6048d4ef25a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -20,20 +20,12 @@ namespace XCharts.Example
}
}
float m_LastTime = 0;
double m_Value = 0;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
//AddData();
OnTestBtn();
}
if (Time.time - m_LastTime > 0.1f)
{
m_LastTime = Time.time;
chart.UpdateData(0, 2, m_Value);
m_Value += 15;
AddData();
//OnTestBtn();
}
}