Unity插件XCharts 图表
参考网址:Unity插件XCharts_xcharts unity_Raki_0的博客-CSDN博客
XCharts 下载地址 :Unity插件XCharts资源-CSDN文库
github 地址:Releases · XCharts-Team/XCharts · GitHub
一.导入教程
1.直接放入XCharts源码到项目
下载好XCharts源码后,直接将XCharts目录拷贝到Unity项目工程的Assets目录下。
2. 通过Assets/Import Package导入XCharts
下载好XCharts的.unitypackage文件后,打开Unity,菜单栏 Assets–>Import Package–>选中.unitypackage导入即可开始使用XCharts。
二.创建
1.在Hierarchy试图下右键XCharts->LineChart
2.菜单栏GameObject下拉XCharts->LineChart
3.修改图表参数
Y的数据 会根据data 变化自动增长 图表的数值
x 需要专门设置 x轴数据 (默认是5x)
三.动态增加改变参数
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XCharts.Runtime;
/// <summary>
/// 图表测试
/// </summary>
public class Test : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){var chart = gameObject.GetComponent<LineChart>();if (chart == null){chart = gameObject.AddComponent<LineChart>();chart.Init();//chart.SetSize(580, 300);//代码动态设置尺寸,或直接操作chart.rectTransform,或直接在Inspector上改//var title = chart.GetOrAddChartComponent<Title>();//title.text = "Simple Line";var tooltip = chart.GetOrAddChartComponent<Tooltip>();tooltip.show = true;//var legend = chart.GetOrAddChartComponent<Legend>();//legend.show = false;chart.RemoveData();chart.AddSerie<Line>("line");for (int i = 0; i < 10; i++){chart.AddXAxisData("x" + i);chart.AddData(0, Random.Range(10, 20));}var title = chart.GetOrAddChartComponent<Title>();title.text = "FMC分布特征";title.subText = "normal line";var xAxis = chart.GetOrAddChartComponent<XAxis>();xAxis.splitNumber = 10;xAxis.boundaryGap = true;xAxis.type = Axis.AxisType.Category;}// 有可能会变动,所以初始化RectTransform 的值this.transform.GetComponent<RectTransform>().offsetMax = new Vector2(0,0);this.transform.GetComponent<RectTransform>().offsetMin = new Vector2(0, 0);}// Update is called once per framevoid Update(){}
}