Unity插件XCharts的代码测试简记

Unity插件XCharts的代码测试简记

相关链接

插件作者主页:

插件下载链接:

  1. https://github.com/monitor1394/unity-ugui-XCharts:插件源项目
  2. https://download.csdn.net/download/f_957995490/12189881:我自己导出的unitypackage

创建

如下图指示的创建例子图表(线形图)。
创建图表

代码

编写代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XCharts;

public class XChartsTest : MonoBehaviour
{
    LineChart chart;
    string name1 = "test";
    string name2 = "test2";

    void Awake()
    {
        chart = GetComponent<LineChart>();
    }

    void Start()
    {
        chart.title.show = true;
        chart.title.text = "Line Text";

        chart.tooltip.show = true;

        chart.legend.show = true;
        chart.legend.data.Clear();
        chart.legend.data.Add(name1);
        chart.legend.data.Add(name2);

        chart.xAxises[0].show = true;
        chart.xAxises[1].show = false;
        chart.yAxises[0].show = true;
        chart.yAxises[1].show = false;

        chart.xAxises[0].type = Axis.AxisType.Value;
        chart.yAxises[0].type = Axis.AxisType.Category;


        int[] data1 = { 10, 20, 30, 10, 50 };
        int[] data2 = { 50, 60, 10, 50, 10 };
        chart.xAxises[0].splitNumber = data1.Length;

        chart.RemoveData();

        for (int i = 0; i < data1.Length; i++)
        {
            chart.AddYAxisData(i.ToString());
        }

        chart.AddSerie(SerieType.Line, name1);
        chart.AddSerie(SerieType.Line, name2);

        foreach (int i in data1)
        {
            chart.AddData(name1, i);
        }

        foreach (int i in data2)
        {
            chart.AddData(name2, i);
        }

        time = 0;
    }

    private float time;

    void Update()
    {
        if (2.0f <= time)
        {
            time = 0;
            float temp = Random.Range(10, 70);
            chart.UpdateData(name1, 2, temp);
        }
        time += Time.deltaTime;
    }
}

然后,挂在创建的线形图表上。
挂脚本
运行之后,效果如下:
效果
当然图中的红线2号节点会每2秒钟运动一次。

  • 3
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 14
    评论
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天富儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值