1.基本使用

创建Canvas-->菜单栏快速创建Graph

2.创建完毕后找到Graph Chart脚本 里data,根据实际情况创建几个曲线

3.如果自定义垂直和水平的值,就不要点击Auto,

  graph = GetComponent<GraphChartBase>();graph.DataSource.AutomaticVerticallView = false;graph.DataSource.VerticalViewOrigin = 0;graph.DataSource.VerticalViewSize = 3000;

4.调整垂直和水平的刻度

5 如果感觉点击节点是显示的文字太小或者重写格式,可以找到LtemLabels脚本

6.测试

using UnityEngine;
using ChartAndGraph;
using System.Collections.Generic;
using System;
public class GraphBaseMainMuen : MonoBehaviour, IComparer<DoubleVector2>
{protected List<DoubleVector2> mData = new List<DoubleVector2>();protected double pageSize = 50f;protected double currentPagePosition = 0.0;protected GraphChartBase graph;protected VerticalAxis axis;// Use this for initializationprotected virtual void Awake(){graph = GetComponent<GraphChartBase>();}// 如果您想知道当前显示的索引是什么。使用二分查找来找到它int FindClosestIndex(double position){//NOTE :: 此方法假定您的数据已排序 !!!int res = mData.BinarySearch(new DoubleVector2(position, 0.0), this);if (res >= 0)return res;return ~res;}// 给定页面位置,在该页面的数据中找到最右和最左的索引void findPointsForPage(double position, out int start, out int end){int index = FindClosestIndex(position);int i = index;double endPosition = position + pageSize;double startPosition = position - pageSize;//从当前索引开始,我们发现页面边界for (start = index; start > 0; start--){// 把纸上的第一点拿出来。所以曲线在这条边不会断裂if (mData[i].x < startPosition)break;}for (end = index; end < mData.Count; end++){if (mData[i].x > endPosition) // 把纸上的第一点拿出来break;}}protected string named;protected virtual void Update(){if (graph != null){//检查图形的滚动位置。如果我们超过了视图大小,则loada新页面double pageStartThreshold = currentPagePosition - pageSize;double pageEndThreshold = currentPagePosition + pageSize -graph.DataSource.HorizontalViewSize;if (graph.HorizontalScrolling < pageStartThreshold || graph.HorizontalScrolling > pageEndThreshold){LoadPage(graph.HorizontalScrolling,named);}}}protected void LoadPage(double pagePosition,string name){if (graph != null){// Debug.Log("Loading page :" + pagePosition);graph.DataSource.StartBatch(); // call start batchgraph.DataSource.HorizontalViewOrigin = 0;int start, end;findPointsForPage(pagePosition, out start, out end); // get the page edgesgraph.DataSource.ClearCategory("Player 1"); // clear the cateogryfor (int i = start; i < end; i++) // load the datagraph.DataSource.AddPointToCategory(name, mData[i].x, mData[i].y);graph.DataSource.EndBatch();graph.HorizontalScrolling = pagePosition;}currentPagePosition = pagePosition;}public int Compare(DoubleVector2 x, DoubleVector2 y){if (x.x < y.x)return -1;if (x.x < y.x)return 1;return 0;}
}
using ChartAndGraph;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LitJson;
using UnityEngine.UI;public class Electro : GraphBaseMainMuen
{public static string Url= "/energy/rest/MnitorData/?retry=5&retryDelay=500&time__range=";public static string Arge = "&type=hour&pagesize=9999&order=time&EnergyCategory=5";protected static float NowTimeGross;protected static float OldTimeGross;protected override void Awake(){base.Awake();StartCoroutine(Energewww(NowTime + "," + NextTime, "Player 2"));StartCoroutine( ConstantUtils.B_invoke(() => { StartCoroutine(Energewww(OldTime + "," + NowTime, "Player 1")); },0.5f));}// Update is called once per frameprotected override void Update () {base.Update();}IEnumerator Energewww(string time,string name){WWW www = new WWW(ConstantUtils.ServerUrl+ Url + time + Arge);yield return www;if(www.isDone&&string.IsNullOrEmpty(www.error)){JsonData data = JsonMapper.ToObject(www.text);int count = int.Parse(data["count"].ToString());for (int i = 0; i < count; i++){mData.Add(new DoubleVector2(i, float.Parse( data["results"][i]["D_value"].ToString())));if (name == "Player 2")NowTimeGross += float.Parse(data["results"][i]["D_value"].ToString());elseOldTimeGross += float.Parse(data["results"][i]["D_value"].ToString());}LoadPage(currentPagePosition, name);if(name== "Player 2"){ConstantUtils.GetOrCreat<Text>("CanvasFirst/运维页面/ElectroBG/BG/今日用电量/Text").text = String.Format("{0:F}", NowTimeGross);}else{Debug.Log(Rate(NowTimeGross, OldTimeGross));}}}
}

7.上测试图,目前还可以

饼图

public class PieBase : MonoBehaviour {protected BillboardText oldtext;protected double value;protected CanvasPieChart pieChart;[HideInInspector]public bool isActive;// Use this for initializationpublic virtual void Start () {pieChart = GetComponent<CanvasPieChart>();if (isActive){pieChart.PieHovered.AddListener(Active);pieChart.NonHovered.AddListener(hide);}}private void hide(){oldtext.UIText.GetComponent<Text>().text = value.ToString();}private void Active(PieChart.PieEventArgs arg0){foreach (var i in pieChart.mPies){if(i.Key== arg0.Category){oldtext = i.Value.ItemLabel;value = arg0.Value;i.Value.ItemLabel.UIText.GetComponent<Text>().text = arg0.Category+"\n" + value;}}}// Update is called once per framevoid Update () {}
}

条形图

使用叠加模式需要点上CanvasBarChart脚本中stacked参数

using ChartAndGraph;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class BarBase : MonoBehaviour {public BarChart barChart;// Use this for initializationpublic virtual void Start () {barChart = GetComponent<BarChart>();}// Update is called once per framevoid Update () {}public void BasebarInfo(string category,Material material,float value, string Group = "All" ){barChart.DataSource.StartBatch();barChart.DataSource.AddCategory(category, material);barChart.DataSource.SetValue(category, Group, value);//barChart.DataSource.SlideValue(category, Group, value, 4f);barChart.DataSource.EndBatch();}public void Setval(string category, float value, string Group = "All"){barChart.DataSource.SetValue(category, Group, value);}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;public class BarMain : BarBase
{public List<double> paix = new List<double>();public override void Start(){base.Start();for (int i = 0; i < 4; i++){for (int j = 0; j < 3; j++){if (j == 0){int x = Random.Range(30, 50);paix.Add(x);barChart.DataSource.SetValue(barChart.DataSource.GetCategoryName(j), barChart.DataSource.GetGroupName(i), x);}else{double x=  Random.Range(10, 40);paix.Add(x);barChart.DataSource.SetValue(barChart.DataSource.GetCategoryName(j), barChart.DataSource.GetGroupName(i), barChart.DataSource.GetValue(barChart.DataSource.GetCategoryName(j - 1), barChart.DataSource.GetGroupName(i)) +x);}}//  barChart.DataSource.SetCategoryIndex(i + "1标", i);}barChart.isok = true;}public void M_ItemRotate(){int c = 0;if (barChart.mBars == null)return;foreach (var i in barChart.mBars){i.Value.ItemLabel.UIText.GetComponent<Text>().text= paix[c].ToString();c++;}Transform ds = transform.Find("New Game Object/textController");for (int i=0;i< ds.childCount;i++){ds.GetChild(i).localEulerAngles = new Vector3(0, 0, 90);}}

Unity3d Chart and Graph插件使用 (2D曲线图,饼图,条形图)相关推荐

  1. 【风宇冲】Unity3D教程宝典之插件篇:Unity3D插件详细评测及教学下载

    [风宇冲]Unity3D教程宝典之插件篇:Unity3D插件详细评测及教学下载 (2012-12-09 07:27:51) 转载▼ 标签: unity3d unity unity3d教程 unity3 ...

  2. Chart and Graph

    Unity2019.4.17f1c1 测试 Chart and Graph 图标插件 参考视频 https://www.bilibili.com/video/BV18p4y1a7zJ/?spm_id_ ...

  3. Unity3D引擎各大插件免费下载地址

    Unity3D引擎作为当前最主流的3D游戏引擎之一,拥有大量第三方插件和工具.以下为各大Unity3D引擎各大插件免费下载地址,还有一些热门插件例如:Playmaker . UnIDE .Tile B ...

  4. 免费资源分享(六) Unity3D 雷达实时定位插件

    免费分享 Unity3D 雷达实时定位插件. 适应版本:Unity 2018.4 链接:https://pan.baidu.com/s/1kE6uTSs70liY2l7GK3r7Eg 提取码:7dw1 ...

  5. Unity3D中使用easyroad3d插件 删除道路

    Unity3D中使用easyroad3d插件 删除道路操作方法: 在"Hierarchy"中选中你新建的road的名称,点击展开,会有一个名为"Markers" ...

  6. 2019年4月份整理的Unity3D 20个实用插件-免费下载

    Unity3D 简易细节层次插件 Simple LOD http://www.idoubi.net/unity3d/tool/3764.html Unity3D 物体表面贴花喷漆插件 Easy Dec ...

  7. Unity3D插件 AnyPortrait 2D骨骼动画制作

    一.前言 AnyPortrait是一个创建2D角色动画制作的Unity拓展编辑器插件. AnyPortrait提供了很多功能,让你可以在Unity里面就完成动画的制作. 使用AnyPortrait插件 ...

  8. Unity3D常用游戏开发插件测评总结

    Unity3D插件详细评测及教学下载 分类: unity3d2013-12-13 11:29 2230人阅读 评论(0) 收藏 举报 unity3d插件 转载自风宇冲Unity3D教程学院 本文一共分 ...

  9. Unity3D教程宝典之插件篇:Unity3D插件详细评测及教学下载

    原创文章如需转载请注明:转载自风宇冲Unity3D教程学院 引言:想用Unity3D制作优秀的游戏,插件是必不可少的.工欲善其事必先利其器.本文主旨是告诉使用Unity3D引擎的同学们如何根据需求选择 ...

最新文章

  1. java web开发周志_javaweb学习笔记及周报告
  2. golang 解析php序列化,golang实现php里的serialize()和unserialize()序列和反序列方法详解...
  3. OSError: [WinError 126] 找不到指定的模块/Could not find 'cudart64_90.dll'.
  4. 安装apache+gd2(jpeg,png等)+mysql-client+php脚本
  5. 【快乐水题】1518. 换酒问题
  6. 计算未来轻沙龙 | 当深度学习遇上归纳推理,图神经网络有多强大?
  7. php 输入内容类型,实例解析php的数据类型
  8. 企业内部信息化项目管理之我所见
  9. matlab常用函数辨析
  10. 《走遍中国》珍藏版(二)
  11. 《Python Cookbook 3rd》笔记(3.6):复数的数学运算
  12. mysql 本地连接_mysql开启远程连接及本地连接
  13. HDU 2844 Coins 多重背包
  14. ubuntu使用pytorch训练出现killed_目标检测之pytorch预训练模型的使用(削减削减网络层,修改参数)fine-tune技巧...
  15. Note: the configuration keeps the entry point 'XXX', but not the descriptor class 'XXX'
  16. Jeecgboot报错Failed to configure a DataSource: ‘unl‘ attribute is not specified and no embedded dataso
  17. group by 按某一时间段分组统计并查询
  18. 购买计算机一定要追求独立显卡,购买电脑的常识.pptx
  19. 洛谷:P1033 [NOIP2002 提高组] 自由落体 C++详解
  20. UMeditor百度富文本编辑器的使用

热门文章

  1. MUI 的学习与使用
  2. 华为云王红新_Veritas 与华为云签署合作谅解备忘录 推进云数据安全进阶
  3. Java解析PPT获取文本和图片
  4. dataguard跨平台linux,Dataguard从库性能的监控
  5. 如何把手机计算机图标放到桌面,手机桌面图标怎么设置,桌面图标主题包
  6. “学而优”在线考试系统的商业模式
  7. phpstorm优雅的格式化php代码
  8. 问答积分体系:声望值
  9. HTML学生个人网站作业设计:动漫网站设计——动漫海贼王(5页) HTML+CSS+JavaScript 简单DIV布局个人介绍网页模板代码 DW学生个人网站制作成品下载
  10. 【转自猫大】宏定义的黑魔法 - 宏菜鸟起飞手册