增加Demo首页,展示代码控制效果

This commit is contained in:
monitor1394
2019-10-16 18:46:31 +08:00
parent 620cdf78c7
commit 6b66b5a129
7 changed files with 210686 additions and 19467 deletions

View File

@@ -0,0 +1,301 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XCharts;
[DisallowMultipleComponent]
public class Demo00_CheatSheet : MonoBehaviour
{
private LineChart chart;
private float speed = 100f;
void Awake()
{
LoopDemo();
}
private void OnEnable()
{
LoopDemo();
}
void LoopDemo()
{
StopAllCoroutines();
StartCoroutine(CheatSheet());
}
IEnumerator CheatSheet()
{
StartCoroutine(InitChart());
StartCoroutine(ComponentTitle());
yield return new WaitForSeconds(3);
StartCoroutine(ComponentAxis());
yield return new WaitForSeconds(3);
StartCoroutine(ComponentGrid());
yield return new WaitForSeconds(3);
StartCoroutine(ComponentSerie());
yield return new WaitForSeconds(5);
StartCoroutine(ComponentLegend());
yield return new WaitForSeconds(7);
StartCoroutine(ComponentTheme());
yield return new WaitForSeconds(6);
StartCoroutine(ComponentDataZoom());
yield return new WaitForSeconds(10);
StartCoroutine(ComponentVisualMap());
yield return new WaitForSeconds(5);
LoopDemo();
}
IEnumerator InitChart()
{
chart = gameObject.GetComponent<LineChart>();
if (chart == null) gameObject.AddComponent<LineChart>();
chart.title.show = true;
chart.title.text = "术语解析-组件";
chart.grid.bottom = 30;
chart.grid.right = 30;
chart.grid.left = 30;
chart.grid.top = 80;
chart.dataZoom.enable = false;
chart.visualMap.enable = false;
chart.RemoveData();
chart.AddSerie(SerieType.Bar, "Bar");
chart.AddSerie(SerieType.Line, "Line");
for (int i = 0; i < 8; i++)
{
chart.AddXAxisData("x" + (i + 1));
chart.AddData(0, Random.Range(10, 100));
chart.AddData(1, Random.Range(10, 100));
}
yield return null;
}
IEnumerator ComponentTitle()
{
chart.title.text = "术语解析 - 组件";
chart.title.subText = "Title 标题:可指定主标题和子标题";
chart.xAxis0.show = true;
chart.yAxis0.show = true;
chart.series.list[0].show = false;
chart.series.list[1].show = false;
chart.legend.show = false;
for (int i = 0; i < 4; i++)
{
chart.title.show = !chart.title.show;
chart.RefreshChart();
yield return new WaitForSeconds(0.3f);
}
chart.title.show = true;
chart.RefreshChart();
}
IEnumerator ComponentAxis()
{
chart.title.subText = "Axis 坐标轴配置X和Y轴的轴线、刻度、标签等样式外观配置";
chart.series.list[0].show = false;
chart.series.list[1].show = false;
for (int i = 0; i < 4; i++)
{
chart.xAxis0.show = !chart.xAxis0.show;
chart.yAxis0.show = !chart.yAxis0.show;
chart.RefreshChart();
yield return new WaitForSeconds(0.4f);
}
chart.xAxis0.show = true;
chart.yAxis0.show = true;
chart.RefreshChart();
yield return new WaitForSeconds(2f);
}
IEnumerator ComponentGrid()
{
chart.title.subText = "Grid 网格:调整坐标系边距和颜色等";
for (int i = 0; i < 4; i++)
{
chart.grid.backgroundColor = i % 2 == 0 ? Color.clear : Color.grey;
chart.RefreshChart();
yield return new WaitForSeconds(0.4f);
}
chart.grid.backgroundColor = Color.clear;
chart.RefreshChart();
yield return new WaitForSeconds(2f);
}
IEnumerator ComponentSerie()
{
chart.title.subText = "Serie 系列:调整坐标系边距和颜色等";
chart.series.list[0].show = true;
chart.series.list[1].show = true;
chart.AnimationReset();
chart.RefreshChart();
yield return new WaitForSeconds(1.5f);
for (int i = 0; i < 4; i++)
{
chart.series.list[0].show = !chart.series.list[0].show;
chart.series.list[1].show = !chart.series.list[1].show;
chart.RefreshChart();
yield return new WaitForSeconds(0.4f);
}
chart.series.list[0].show = true;
chart.series.list[1].show = true;
chart.RefreshChart();
yield return new WaitForSeconds(2f);
}
IEnumerator ComponentLegend()
{
chart.title.subText = "Legend 图例:展示不同系列的名字和颜色,可控制系列显示等";
chart.legend.show = true;
chart.grid.top = 80;
chart.legend.location.top = 50;
chart.RefreshChart();
yield return new WaitForSeconds(1.5f);
for (int i = 0; i < 4; i++)
{
chart.legend.show = !chart.legend.show;
chart.RefreshChart();
yield return new WaitForSeconds(0.4f);
}
chart.legend.show = true;
chart.RefreshChart();
yield return new WaitForSeconds(1f);
chart.ClickLegendButton(0, "Line", false);
yield return new WaitForSeconds(0.5f);
chart.ClickLegendButton(0, "Line", true);
yield return new WaitForSeconds(1f);
chart.ClickLegendButton(1, "Bar", false);
yield return new WaitForSeconds(0.5f);
chart.ClickLegendButton(1, "Bar", true);
yield return new WaitForSeconds(1f);
}
IEnumerator ComponentTheme()
{
chart.title.subText = "Theme 主题:可从全局上配置图表的颜色、字体等效果,支持默认主题切换";
yield return new WaitForSeconds(1f);
chart.title.subText = "Theme 主题Light主题";
chart.UpdateTheme(Theme.Light);
yield return new WaitForSeconds(1.5f);
chart.title.subText = "Theme 主题Dark主题";
chart.UpdateTheme(Theme.Dark);
yield return new WaitForSeconds(1.5f);
chart.title.subText = "Theme 主题Default主题";
chart.UpdateTheme(Theme.Default);
yield return new WaitForSeconds(1.5f);
}
IEnumerator ComponentDataZoom()
{
chart.title.subText = "DataZoom 区域缩放:可通过拖、拽、缩小、放大来观察细节数据";
chart.grid.bottom = 70;
chart.dataZoom.enable = true;
chart.dataZoom.supportInside = true;
chart.dataZoom.supportSlider = true;
chart.dataZoom.height = 30;
chart.dataZoom.start = 0;
chart.dataZoom.end = 100;
chart.RefreshChart();
for (int i = 0; i < 4; i++)
{
chart.dataZoom.supportSlider = !chart.dataZoom.supportSlider;
chart.RefreshChart();
yield return new WaitForSeconds(0.4f);
}
chart.dataZoom.supportSlider = true;
chart.RefreshChart();
yield return new WaitForSeconds(1f);
while (chart.dataZoom.start < 40)
{
chart.dataZoom.start += speed * Time.deltaTime * 0.5f;
chart.RefreshDataZoom();
chart.RefreshChart();
yield return null;
}
while (chart.dataZoom.end > 60)
{
chart.dataZoom.end -= speed * Time.deltaTime * 0.5f;
chart.RefreshDataZoom();
chart.RefreshChart();
yield return null;
}
while (chart.dataZoom.start > 0)
{
chart.dataZoom.start -= speed * Time.deltaTime * 0.5f;
chart.dataZoom.end -= speed * Time.deltaTime * 0.5f;
chart.RefreshDataZoom();
chart.RefreshChart();
yield return null;
}
while (chart.dataZoom.end < 100)
{
chart.dataZoom.start += speed * Time.deltaTime * 0.5f;
chart.dataZoom.end += speed * Time.deltaTime * 0.5f;
chart.RefreshDataZoom();
chart.RefreshChart();
yield return null;
}
while (chart.dataZoom.start > 0 || chart.dataZoom.end < 100)
{
chart.dataZoom.start -= speed * Time.deltaTime * 0.5f;
chart.dataZoom.end += speed * Time.deltaTime * 0.5f;
chart.RefreshDataZoom();
chart.RefreshChart();
yield return null;
}
}
IEnumerator ComponentVisualMap()
{
chart.title.subText = "VisualMap 视觉映射:可从全局上配置图表的颜色、字体等效果,支持默认主题切换";
chart.visualMap.enable = true;
chart.visualMap.show = true;
chart.visualMap.orient = Orient.Vertical;
chart.visualMap.calculable = true;
chart.visualMap.min = 0;
chart.visualMap.max = 100;
chart.visualMap.range[0] = 0;
chart.visualMap.range[1] = 100;
var colors = new List<string>{"#313695", "#4575b4", "#74add1", "#abd9e9", "#e0f3f8", "#ffffbf",
"#fee090", "#fdae61", "#f46d43", "#d73027", "#a50026"};
chart.visualMap.inRange.Clear();
foreach (var str in colors)
{
chart.visualMap.inRange.Add(ThemeInfo.GetColor(str));
}
chart.grid.left = 80;
chart.grid.bottom = 100;
chart.RefreshChart();
yield return new WaitForSeconds(1f);
while (chart.visualMap.rangeMin < 40)
{
chart.visualMap.rangeMin += speed * Time.deltaTime;
chart.RefreshChart();
yield return null;
}
while (chart.visualMap.rangeMax > 60)
{
chart.visualMap.rangeMax -= speed * Time.deltaTime;
chart.RefreshChart();
yield return null;
}
while (chart.visualMap.rangeMin > 0 || chart.visualMap.rangeMax < 100)
{
chart.visualMap.rangeMin -= speed * Time.deltaTime;
chart.visualMap.rangeMax += speed * Time.deltaTime;
chart.RefreshChart();
yield return null;
}
}
}

View File

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

View File

@@ -1,20 +1,197 @@
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
using XCharts;
[DisallowMultipleComponent]
[ExecuteInEditMode]
public class Demo30_Pie : MonoBehaviour
{
private PieChart chart;
private Serie serie, serie1;
private float m_RadiusSpeed = 100f;
private float m_CenterSpeed = 1f;
void Awake()
{
LoopDemo();
}
private void OnEnable()
{
LoopDemo();
}
void LoopDemo()
{
StopAllCoroutines();
StartCoroutine(PieDemo());
}
IEnumerator PieDemo()
{
StartCoroutine(PieAdd());
yield return new WaitForSeconds(2);
StartCoroutine(PieShowLabel());
yield return new WaitForSeconds(4);
StartCoroutine(Doughnut());
yield return new WaitForSeconds(3);
StartCoroutine(DoublePie());
yield return new WaitForSeconds(2);
StartCoroutine(RosePie());
yield return new WaitForSeconds(5);
LoopDemo();
}
IEnumerator PieAdd()
{
chart = gameObject.GetComponent<PieChart>();
if (chart == null) return;
var serie = chart.series.GetSerie(0);
var serieData = serie.GetSerieData(0);
serieData.radius = 100;
if (chart == null) chart = gameObject.AddComponent<PieChart>();
chart.title.text = "饼图";
chart.title.subText = "基础饼图";
chart.legend.show = true;
chart.legend.location.align = Location.Align.TopLeft;
chart.legend.location.top = 60;
chart.legend.location.left = 2;
chart.legend.itemWidth = 70;
chart.legend.itemHeight = 20;
chart.legend.orient = Orient.Vertical;
chart.RemoveData();
serie = chart.AddSerie(SerieType.Pie, "访问来源");
serie.pieRadius[0] = 0;
serie.pieRadius[1] = 110;
serie.pieCenter[0] = 0.5f;
serie.pieCenter[1] = 0.4f;
chart.AddData(0, 335, "直接访问");
chart.AddData(0, 310, "邮件营销");
chart.AddData(0, 243, "联盟广告");
chart.AddData(0, 135, "视频广告");
chart.AddData(0, 1548, "搜索引擎");
chart.RefreshLabel();
yield return new WaitForSeconds(1);
}
IEnumerator PieShowLabel()
{
chart.title.subText = "显示文本标签";
serie.label.show = true;
chart.RefreshChart();
yield return new WaitForSeconds(1);
serie.label.lineType = SerieLabel.LineType.Curves;
chart.RefreshChart();
yield return new WaitForSeconds(1);
serie.label.lineType = SerieLabel.LineType.HorizontalLine;
chart.RefreshChart();
yield return new WaitForSeconds(1);
serie.label.lineType = SerieLabel.LineType.BrokenLine;
chart.RefreshChart();
yield return new WaitForSeconds(1);
serie.label.show = false;
chart.RefreshChart();
}
IEnumerator Doughnut()
{
chart.title.subText = "圆环图";
serie.pieRadius[0] = 2f;
while (serie.pieRadius[0] < serie.pieRadius[1] * 0.7f)
{
serie.pieRadius[0] += m_RadiusSpeed * Time.deltaTime;
chart.RefreshChart();
yield return null;
}
serie.pieSpace = 1f;
chart.RefreshChart();
yield return new WaitForSeconds(1);
serie.data[0].selected = true;
chart.RefreshChart();
yield return new WaitForSeconds(1);
serie.pieSpace = 0f;
serie.data[0].selected = false;
chart.RefreshChart();
yield return new WaitForSeconds(1);
}
IEnumerator DoublePie()
{
chart.title.subText = "多图组合";
serie1 = chart.AddSerie(SerieType.Pie, "访问来源2");
chart.AddData(1, 335, "直达");
chart.AddData(1, 679, "营销广告");
chart.AddData(1, 1548, "搜索引擎");
serie1.pieRadius[0] = 0;
serie1.pieRadius[1] = 2f;
serie1.pieCenter[0] = 0.5f;
serie1.pieCenter[1] = 0.4f;
chart.RefreshChart();
while (serie1.pieRadius[1] < serie.pieRadius[0] * 0.75f)
{
serie1.pieRadius[1] += m_RadiusSpeed * Time.deltaTime;
chart.RefreshChart();
yield return null;
}
serie1.label.show = true;
serie1.label.position = SerieLabel.Position.Inside;
serie1.label.color = Color.white;
serie1.label.fontSize = 14;
serie1.label.border = false;
chart.RefreshLabel();
chart.RefreshChart();
yield return new WaitForSeconds(1);
}
IEnumerator RosePie()
{
chart.title.subText = "玫瑰图";
chart.legend.show = false;
serie1.ClearData();
serie.ClearData();
serie1.pieRadius = serie.pieRadius = new float[2] { 0, 80 };
serie1.label.position = SerieLabel.Position.Outside;
serie1.label.lineType = SerieLabel.LineType.Curves;
serie1.label.color = Color.clear;
for (int i = 0; i < 2; i++)
{
chart.AddData(i, 10, "rose1");
chart.AddData(i, 5, "rose2");
chart.AddData(i, 15, "rose3");
chart.AddData(i, 25, "rose4");
chart.AddData(i, 20, "rose5");
chart.AddData(i, 35, "rose6");
chart.AddData(i, 30, "rose7");
chart.AddData(i, 40, "rose8");
}
while (serie.pieCenter[0] > 0.25f || serie1.pieCenter[0] < 0.7f)
{
if (serie.pieCenter[0] > 0.25f) serie.pieCenter[0] -= m_CenterSpeed * Time.deltaTime;
if (serie1.pieCenter[0] < 0.7f) serie1.pieCenter[0] += m_CenterSpeed * Time.deltaTime;
chart.RefreshChart();
yield return null;
}
yield return new WaitForSeconds(1);
while (serie.pieRadius[0] > 3f)
{
serie.pieRadius[0] -= m_RadiusSpeed * Time.deltaTime;
serie1.pieRadius[0] -= m_RadiusSpeed * Time.deltaTime;
chart.RefreshChart();
yield return null;
}
serie.pieRadius[0] = 0;
serie1.pieRadius[0] = 0;
serie.pieRoseType = RoseType.Area;
serie1.pieRoseType = RoseType.Radius;
chart.RefreshChart();
yield return new WaitForSeconds(1);
}
}

32
Demo/Scripts/Demo_Test.cs Normal file
View File

@@ -0,0 +1,32 @@
using UnityEngine;
using UnityEngine.UI;
using XCharts;
[DisallowMultipleComponent]
[ExecuteInEditMode]
public class Demo_Test : MonoBehaviour
{
LineChart chart;
void Awake()
{
chart = gameObject.GetComponent<LineChart>();
if (chart == null)
{
chart = gameObject.AddComponent<LineChart>();
}
var buttom = transform.parent.gameObject.GetComponentInChildren<Button>();
buttom.onClick.AddListener(AddData);
}
void AddData()
{
chart.series.list[0].ClearData();
chart.series.list[1].ClearData();
for (int i = 0; i < 5; i++)
{
chart.AddData(0, Random.Range(20, 100));
chart.AddData(1, Random.Range(1, 10));
}
}
}

View File

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