Chart and Graph

吴浩博
2023-12-01

Unity2019.4.17f1c1 测试 Chart and Graph 图标插件

参考视频

https://www.bilibili.com/video/BV18p4y1a7zJ/?spm_id_from=333.788.recommend_more_video.13
示例 Themes/2d/Graph/preset 7/GraphChart

找个对象 挂在脚本 Graph Chart 这里示例 挂在的是GraphChart对象上 
找到Data/Categories/Player 1  ...   /四种选择:Move Up(向上) 、 Move Down (向下)、 Remove (删除)、 Rename(重命名)
每个Player 1里面都有相同的内容 其中Line Thickness 调整划线的粗细程度  Add new category:  新增一个
视频中创建 一个新的脚本 

using ChartAndGraph;引用了这个命名空间 

public GraphChart chart;  

在Start函数里 写上chart.DataSource.AddPointToCategory("这里写你监视器面板上的名字如果没改 默认是Player 1",0,0);
然后视频中复制了这个修改参数
DataInitializer对象上挂上写的这个脚本 (这个对象没看出来什么特别只是个空对象)接着拖入GraphChart 运行就可以显示图表了

在StartBatch更改图
chart.DataSource.StartBatch();
在新数据类别填充前清理
chart.DataSource.ClearCategory("名字传入进来");

中间是内容******************
******************************
******************************

对第二种情况做同样处理
chart.DataSource.ClearCategory("名字传入进来");
chart.DataSource.AddPointToCategory("这里写你监视器面板上的名字如果没改 默认是Player 2",0,0);
中间是内容******************
******************************
******************************


每个startBatch调用必须与EndBatch调用匹配
chart.DataSource.EndBatch();
重新绘制图形

在Update函数里做了一些时间更新操作
其中用到的API  AddPointToCategoryRealtime    具体可以照着视频写时间是10分钟左右那会
这样写完运行的话他会一直压缩特别密  可以勾选Fit To Container 和 Scrollable 和 Auto Scroll Horizontally 取消勾选 Horizontal View 
这样就出现滚动状态  除此之外还有其他的一些属性可以更改 Auto 是否自动  Data/Point Size 节点大小 Material 给线改材质 Inner Fill 线段位置往下的所有填充颜色
Vertical Axis脚本 
Font Size 调整Y轴数字大小
Text Seperation 调整Y轴的位置
Alignment 调整Y轴看他位置是居左还是居右
Text Prefab 调整字体
Main Divisions/Units Per Division 调整数量
另外可以新加脚本Item Labels 每个节点上可以看到具体数值  
Font Size调整大小
最后有两个网站可以参考
https://connect.unity.com/p/unityjiao-ben-yu-bian-ji-qi-gong-ju-kai-fa-sheng-shi-bi-bei-li-qi
https://blog.csdn.net/qq_39873732/article/details/88973135

测试

using UnityEngine;
using ChartAndGraph;//引用命名空间

public class TestCubeMan : MonoBehaviour
{
    public GraphChart chart;

    private float timer = 1f;
    private float x = 4f;

    private void Start()
    {
        //在开始处理或结束处理的时候调用
        //It is also best practice to enclose graph changes in StartBatch and EndBatch calls
        chart.DataSource.StartBatch();

        //使用新数据之前清空原来的
        //chart.DataSource.ClearCategory("名字");
        chart.DataSource.ClearCategory("CubeManHandRight");

        //测试通过AddPointToCategory这个方法可以生成图表
        //chart.DataSource.AddPointToCategory("名字", x轴, y轴);
        chart.DataSource.AddPointToCategory("CubeManHandRight", 0, 1);
        chart.DataSource.AddPointToCategory("CubeManHandRight", 1, 2);
        chart.DataSource.AddPointToCategory("CubeManHandRight", 2, 3);
        chart.DataSource.AddPointToCategory("CubeManHandRight", 3, 4);
        chart.DataSource.AddPointToCategory("CubeManHandRight", 4, 5);
        chart.DataSource.AddPointToCategory("CubeManHandRight", 5, 6);

        //如果有第二种类别 可以在绘制第二种 我这里没有 
        //第二种操作步骤同上 先ClearCategory 然后 AddPointToCategory
        //now we do the same for the second category
        /*
         ClearCategory
         AddPointToCategory
         AddPointToCategory
         */

        //有开始处理就要有结束处理 StartBatch 要和 EndBatch 对应
        //each StartBatch call must be matched with an EndBatch call
        chart.DataSource.EndBatch();

        //调用EndBatch重新绘制图表
        //graph is redrawn after EndBatch is called
    }

    private void Update()
    {
        //添加每隔一秒更新一次数据
        //now let's add a streaming data update the goes every 1 second
        
        //更新时间减过去的时间
        timer -= Time.deltaTime;//each update we decrease the time that has passed 
        //如果更新时间小于0
        if (timer <= 0f)
        {
            //时间重新设置回1
            timer = 1f;//set the time to one again and
            //AddPointToCategoryRealtime 实时添加点到类别
            //chart.DataSource.AddPointToCategoryRealtime("名字", x轴, y轴); //为动画设置流动时间 时间设置为1 让他在一秒内融合
            chart.DataSource.AddPointToCategoryRealtime("CubeManHandRight", x, Random.value, 1f); //now we can also set the animation time for the streaming value. setting it to 1 will make it blend in 1 second
            //设置下一个点的距离
            x++; //increase the x value so the next point is 1 unity away
        }

    }
}

 类似资料:

相关阅读

相关文章

相关问答