mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 10:20:10 +00:00
增加Demo首页LineChart的代码动态控制效果
This commit is contained in:
230968
Demo/Prefabs/xchart.prefab
230968
Demo/Prefabs/xchart.prefab
File diff suppressed because it is too large
Load Diff
@@ -56,7 +56,7 @@ public class Demo00_CheatSheet : MonoBehaviour
|
|||||||
chart.title.text = "术语解析-组件";
|
chart.title.text = "术语解析-组件";
|
||||||
chart.grid.bottom = 30;
|
chart.grid.bottom = 30;
|
||||||
chart.grid.right = 30;
|
chart.grid.right = 30;
|
||||||
chart.grid.left = 30;
|
chart.grid.left = 50;
|
||||||
chart.grid.top = 80;
|
chart.grid.top = 80;
|
||||||
|
|
||||||
chart.dataZoom.enable = false;
|
chart.dataZoom.enable = false;
|
||||||
@@ -71,7 +71,7 @@ public class Demo00_CheatSheet : MonoBehaviour
|
|||||||
{
|
{
|
||||||
chart.AddXAxisData("x" + (i + 1));
|
chart.AddXAxisData("x" + (i + 1));
|
||||||
chart.AddData(0, Random.Range(10, 100));
|
chart.AddData(0, Random.Range(10, 100));
|
||||||
chart.AddData(1, Random.Range(10, 100));
|
chart.AddData(1, Random.Range(30, 100));
|
||||||
}
|
}
|
||||||
yield return null;
|
yield return null;
|
||||||
}
|
}
|
||||||
|
|||||||
264
Demo/Scripts/Demo10_LineChart.cs
Normal file
264
Demo/Scripts/Demo10_LineChart.cs
Normal file
@@ -0,0 +1,264 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
using XCharts;
|
||||||
|
|
||||||
|
[DisallowMultipleComponent]
|
||||||
|
public class Demo10_LineChart : MonoBehaviour
|
||||||
|
{
|
||||||
|
private LineChart chart;
|
||||||
|
private Serie serie;
|
||||||
|
private float m_RadiusSpeed = 100f;
|
||||||
|
private float m_CenterSpeed = 1f;
|
||||||
|
private int m_DataNum = 8;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
LoopDemo();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
|
LoopDemo();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoopDemo()
|
||||||
|
{
|
||||||
|
StopAllCoroutines();
|
||||||
|
StartCoroutine(PieDemo());
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator PieDemo()
|
||||||
|
{
|
||||||
|
StartCoroutine(AddSimpleLine());
|
||||||
|
yield return new WaitForSeconds(2);
|
||||||
|
StartCoroutine(ChangeLineType());
|
||||||
|
yield return new WaitForSeconds(8);
|
||||||
|
StartCoroutine(LineAreaStyleSettings());
|
||||||
|
yield return new WaitForSeconds(5);
|
||||||
|
StartCoroutine(LineArrowSettings());
|
||||||
|
yield return new WaitForSeconds(2);
|
||||||
|
StartCoroutine(LineSymbolSettings());
|
||||||
|
yield return new WaitForSeconds(7);
|
||||||
|
StartCoroutine(LineLabelSettings());
|
||||||
|
yield return new WaitForSeconds(3);
|
||||||
|
StartCoroutine(LineMutilSerie());
|
||||||
|
yield return new WaitForSeconds(5);
|
||||||
|
LoopDemo();
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator AddSimpleLine()
|
||||||
|
{
|
||||||
|
chart = gameObject.GetComponent<LineChart>();
|
||||||
|
if (chart == null) chart = gameObject.AddComponent<LineChart>();
|
||||||
|
chart.title.text = "LineChart - 折线图";
|
||||||
|
chart.title.subText = "普通折线图";
|
||||||
|
|
||||||
|
chart.yAxis0.minMaxType = Axis.AxisMinMaxType.Custom;
|
||||||
|
chart.yAxis0.min = 0;
|
||||||
|
chart.yAxis0.max = 100;
|
||||||
|
|
||||||
|
chart.RemoveData();
|
||||||
|
serie = chart.AddSerie(SerieType.Line, "Line");
|
||||||
|
|
||||||
|
for (int i = 0; i < m_DataNum; i++)
|
||||||
|
{
|
||||||
|
chart.AddXAxisData("x" + (i + 1));
|
||||||
|
chart.AddData(0, UnityEngine.Random.Range(30, 90));
|
||||||
|
}
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator ChangeLineType()
|
||||||
|
{
|
||||||
|
chart.title.subText = "LineTyle - 曲线图";
|
||||||
|
serie.lineType = LineType.Smooth;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
chart.title.subText = "LineTyle - 阶梯线图";
|
||||||
|
serie.lineType = LineType.StepStart;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
serie.lineType = LineType.StepMiddle;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
serie.lineType = LineType.StepEnd;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
chart.title.subText = "LineTyle - 虚线";
|
||||||
|
serie.lineType = LineType.Dash;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
chart.title.subText = "LineTyle - 点线";
|
||||||
|
serie.lineType = LineType.Dot;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
chart.title.subText = "LineTyle - 点划线";
|
||||||
|
serie.lineType = LineType.DashDot;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
chart.title.subText = "LineTyle - 双点划线";
|
||||||
|
serie.lineType = LineType.DashDotDot;
|
||||||
|
chart.RefreshChart();
|
||||||
|
|
||||||
|
serie.lineType = LineType.Normal;
|
||||||
|
chart.RefreshChart();
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator LineAreaStyleSettings()
|
||||||
|
{
|
||||||
|
chart.title.subText = "AreaStyle 面积图";
|
||||||
|
|
||||||
|
serie.areaStyle.show = true;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1f);
|
||||||
|
|
||||||
|
chart.title.subText = "AreaStyle 面积图";
|
||||||
|
serie.lineType = LineType.Smooth;
|
||||||
|
serie.areaStyle.show = true;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1f);
|
||||||
|
|
||||||
|
chart.title.subText = "AreaStyle 面积图 - 调整透明度";
|
||||||
|
while (serie.areaStyle.opacity > 0.4)
|
||||||
|
{
|
||||||
|
serie.areaStyle.opacity -= 0.6f * Time.deltaTime;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
chart.title.subText = "AreaStyle 面积图 - 渐变";
|
||||||
|
serie.areaStyle.toColor = Color.white;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator LineArrowSettings()
|
||||||
|
{
|
||||||
|
chart.title.subText = "LineArrow 头部箭头";
|
||||||
|
serie.lineArrow.show = true;
|
||||||
|
serie.lineArrow.position = LineArrow.Position.Start;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
chart.title.subText = "LineArrow 尾部箭头";
|
||||||
|
serie.lineArrow.position = LineArrow.Position.End;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
serie.lineArrow.show = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// SerieSymbol 相关设置
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
IEnumerator LineSymbolSettings()
|
||||||
|
{
|
||||||
|
chart.title.subText = "SerieSymbol 图形标记";
|
||||||
|
while (serie.symbol.size < 5)
|
||||||
|
{
|
||||||
|
serie.symbol.size += 2.5f * Time.deltaTime;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
chart.title.subText = "SerieSymbol 图形标记 - 空心圆";
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
chart.title.subText = "SerieSymbol 图形标记 - 实心圆";
|
||||||
|
serie.symbol.type = SerieSymbolType.Circle;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
chart.title.subText = "SerieSymbol 图形标记 - 三角形";
|
||||||
|
serie.symbol.type = SerieSymbolType.Triangle;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
chart.title.subText = "SerieSymbol 图形标记 - 正方形";
|
||||||
|
serie.symbol.type = SerieSymbolType.Rect;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
chart.title.subText = "SerieSymbol 图形标记 - 菱形";
|
||||||
|
serie.symbol.type = SerieSymbolType.Diamond;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
chart.title.subText = "SerieSymbol 图形标记";
|
||||||
|
serie.symbol.type = SerieSymbolType.EmptyCircle;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// SerieLabel相关配置
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
IEnumerator LineLabelSettings()
|
||||||
|
{
|
||||||
|
chart.title.subText = "SerieLabel 文本标签";
|
||||||
|
serie.label.show = true;
|
||||||
|
serie.label.border = false;
|
||||||
|
chart.RefreshChart();
|
||||||
|
while (serie.label.offset[1] < 20)
|
||||||
|
{
|
||||||
|
serie.label.offset = new Vector3(serie.label.offset.x, serie.label.offset.y + 20f * Time.deltaTime);
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
serie.label.border = true;
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
serie.label.color = Color.white;
|
||||||
|
serie.label.backgroundColor = Color.grey;
|
||||||
|
chart.RefreshLabel();
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
serie.label.show = false;
|
||||||
|
chart.RefreshChart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加多条线图
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
IEnumerator LineMutilSerie()
|
||||||
|
{
|
||||||
|
chart.title.subText = "多系列";
|
||||||
|
var serie2 = chart.AddSerie(SerieType.Line, "Line2");
|
||||||
|
serie2.lineType = LineType.Normal;
|
||||||
|
for (int i = 0; i < m_DataNum; i++)
|
||||||
|
{
|
||||||
|
chart.AddData(1, UnityEngine.Random.Range(30, 90));
|
||||||
|
}
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
var serie3 = chart.AddSerie(SerieType.Line, "Line3");
|
||||||
|
serie3.lineType = LineType.Normal;
|
||||||
|
for (int i = 0; i < m_DataNum; i++)
|
||||||
|
{
|
||||||
|
chart.AddData(2, UnityEngine.Random.Range(30, 90));
|
||||||
|
}
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
|
||||||
|
chart.yAxis0.minMaxType = Axis.AxisMinMaxType.Default;
|
||||||
|
chart.title.subText = "多系列 - 堆叠";
|
||||||
|
serie.stack = "samename";
|
||||||
|
serie2.stack = "samename";
|
||||||
|
serie3.stack = "samename";
|
||||||
|
chart.RefreshChart();
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 75496d488607d421fbf2c190f80ed0a7
|
guid: d85cdc6ed0e52439887e284e08a8456e
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -3,7 +3,7 @@ using XCharts;
|
|||||||
|
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
[ExecuteInEditMode]
|
[ExecuteInEditMode]
|
||||||
public class Demo10_LineSimple : MonoBehaviour
|
public class Demo13_LineSimple : MonoBehaviour
|
||||||
{
|
{
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 00a8daeea9dce492c8c1ed93c90ae409
|
guid: ac1b93a71505541fe9524658982e7051
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -3,7 +3,7 @@ using UnityEngine;
|
|||||||
using XCharts;
|
using XCharts;
|
||||||
|
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public class Demo30_Pie : MonoBehaviour
|
public class Demo30_PieChart : MonoBehaviour
|
||||||
{
|
{
|
||||||
private PieChart chart;
|
private PieChart chart;
|
||||||
private Serie serie, serie1;
|
private Serie serie, serie1;
|
||||||
@@ -45,7 +45,7 @@ public class Demo30_Pie : MonoBehaviour
|
|||||||
{
|
{
|
||||||
chart = gameObject.GetComponent<PieChart>();
|
chart = gameObject.GetComponent<PieChart>();
|
||||||
if (chart == null) chart = gameObject.AddComponent<PieChart>();
|
if (chart == null) chart = gameObject.AddComponent<PieChart>();
|
||||||
chart.title.text = "饼图";
|
chart.title.text = "PieChart - 饼图";
|
||||||
chart.title.subText = "基础饼图";
|
chart.title.subText = "基础饼图";
|
||||||
|
|
||||||
chart.legend.show = true;
|
chart.legend.show = true;
|
||||||
11
Demo/Scripts/Demo30_PieChart.cs.meta
Normal file
11
Demo/Scripts/Demo30_PieChart.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c9ee113d74ada442196e4e5587795c61
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
15828
Demo/demo_xchart.unity
15828
Demo/demo_xchart.unity
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user