当前位置:网站首页>Unity接入ChartAndGraph图表插件
Unity接入ChartAndGraph图表插件
2022-07-25 05:22:00 【不为誰而做的程序员_】
说明
最近项目上需要实现部分图表数据显示,因为需要用到一些3D图表,所以选择了ChartAndGraph这款图表插件,图表数据是通过后台接口读取Json并解析,然后调用图表插件API将数据显示出来。
一、实现柱状图
实现效果

实现步骤
- 创建柱形图预设如下图,Tools-Charts-Bar-Canvas-Simple创建一个柱形图预设。

- 通过在Insperctor面板中设置相关参数
在上述步骤创建的柱形图预设中找到Canvas Bar Chart脚本组件,列举一下常用设置
柱形图数据设置:其中Categories就是X轴向的内容(但不是在图表下X轴显示的数据),Groups是组名,点击对应后面三个点可以修改移出等操作。
Y轴数据设置:Y轴数据实在柱形图组件上的Vertical Axis脚本组件上控制,常用设置如下:
Format:包含四种数据类型Number、Time、Date、Date Time四种数据(这里是只能选取这四种数据类型,如果Y轴的值,上述四种类型满足不了,可能需要扩展一下插件来支持动态指定)
Text Prefix:Y轴值的前缀
Text Suffix:Y轴文本的后缀
Main Divisions:是主分区的设置,其下的Total是设置有Y轴有多少个数据
Sub Divisions:是子分区的设置,其下的Total是设置有Y轴有多少个数据
- 通过脚本动态加载数据,其余的一些设置也可以通过代码获取到,大家可以试一下。
canvasBarChart_LDSCL=this.GetComponent<CanvasBarChart>();
//数据加载
canvasBarChart_LDSCL.DataSource.StartBatch();
canvasBarChart_LDSCL.DataSource.SetValue("1月", "all", 10);
canvasBarChart_LDSCL.DataSource.SetValue("2月", "all", 10);
canvasBarChart_LDSCL.DataSource.SetValue("3月", "all", 10);
canvasBarChart_LDSCL.DataSource.SetValue("4月", "all", 10);
canvasBarChart_LDSCL.DataSource.SetValue("5月", "all", 10);
canvasBarChart_LDSCL.DataSource.SetValue("6月", "all", 10);
canvasBarChart_LDSCL.DataSource.SetValue("7月", "all", 10);
canvasBarChart_LDSCL.DataSource.EndBatch();
二、实现折线图
实现效果

实现步骤
创建折线图预设如下图,点击Tools-Charts-Graph-Canvas-Simple创建预设。

通过在Insperctor面板中设置相关参数。
在上述步骤创建的柱形图预设中找到Graph Chart脚本组件,列举一下常用设置
Graph Chart脚本组件:
Fit Margin:可以设置X/Y轴的显示起点范围
Categories:折线图数据,可以设置每组数据
Horizontral View: 如勾选自动,起始数值跟结束数值会自动适配,如不想从0开始,就取消勾选通过设置Horizontal View Origin来设置起始点,通过Horizontal View Size 来设置数据的数量
Vertical View:同理
Verical Axis(Y轴设置)基本使用跟上述柱形图一样,不再列举

3.通过脚本动态加载数据
graphChart_MJXY=this.GetComponent<GraphChart>();
graphChart_MJXY.DataSource.StartBatch();
graphChart_MJXY.DataSource.ClearCategory("main");
graphChart_MJXY.DataSource.AddPointToCategory("main", 1, 1);
graphChart_MJXY.DataSource.AddPointToCategory("main", 2, 2);
graphChart_MJXY.DataSource.AddPointToCategory("main", 4, 3);
graphChart_MJXY.DataSource.AddPointToCategory("main", 5, 5);
graphChart_MJXY.DataSource.EndBatch();
遇到的问题
在开发中也遇到的问题,就是X轴的内容显示,因为这个插件X/Y轴的内容只包含了Number、Time、Date、DateTime四种预设类型,开发过程中需要显示不连续的数字,如10、11、12、1、2、3,我是动态添加了一种枚举类型,然后动态的设置X轴的值。还有就是扩展了一些方法。
边栏推荐
- Render Optimization: repaint and reflow
- 深圳随到随考,科目四随到随考,科三理论第二理论随到随考说明
- The second day of rhcsa summer vacation
- systemVerilog中automatic用法
- rhce第一天
- js 页面增加过渡层
- How do novices open accounts for stock speculation? Is it safe for securities companies to open accounts online?
- Solve the problem that uni app applet obtains routes and route parameters
- Sword finger offer special shock edition day 9
- Nexttick principle analysis
猜你喜欢

微服务 - 配置中心 - Nacos

Solution of win11 blue screen code 0x0000001a

Game 302 of leetcode

What should testers do if they encounter a bug that is difficult to reproduce?

easyrecovery免费数据恢复工具操作简单一键恢复数据

项目管理工具——项目开发者工具

STL notes (IV): String

Wechat applet related operation examples

Odoo14 | about the abnormal display of statusbar keyword after use and Its Solutions

An article takes you to understand the sentinel mode of redis
随机推荐
typora+PicGo+阿里云OSS 搭建以及报错解决【转载】
TCL shows a number of folding screen mobile phones: the screen and hinge are independently developed!
How do novices open accounts for stock speculation? Is it safe for securities companies to open accounts online?
Odoo14 | about the abnormal display of statusbar keyword after use and Its Solutions
Openfegin remote call lost request header problem
Shenzhen on call test, subject 4 on call test, subject 3 theory, second theory on call test instructions
批量下载视频小技巧
Now the operator wants to check the answer details of all user questions from Zhejiang University. Please take out the corresponding data
LCP插件创建对等物理接口
微信小程序相关操作示例
JS common code questions array de duplication - Custom New throttling and anti shake - deep copy - instanceof URL parameter extraction - thousand separator - array to tree structure - array flattening
Render Optimization: repaint and reflow
STL notes (I): knowledge system
微服务 - 配置中心 - Nacos
Sword finger offer II 012. the sum of the left and right subarrays is equal
How to carry out the function test with simple appearance and complex interior?
RHCE first day
VIM search and replacement and the use of regular expressions
SystemVerilog中$write与$display区别
Project management tool - Introduction and practice of Alibaba cloud projex