Graph and Chart Study
1.选择主题 “Themes”,以"Graph"——“preset7” 为例;
2.选择“Canvas”——“GraphChart”预制体,1.Set data categories 即“设置数据类型”,each category has it's own visual settings 每个类别都有自己的视觉设置,Line Thickness等‘
3.Now lets feed the chart with data _现在让我们用数据填充图表; Use category names from the inspector(使用检查器中的类别名称)
4.Drag the chart in to the script property(将图表拖到script属性中)
1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 using ChartAndGraph; 5 6 public class MyGraphSample : MonoBehaviour 7 { 8 public GraphChart chart; 9 10 private float Timer = 1f; 11 12 private float X = 10f; 13 // Start is called before the first frame update 14 void Start() 15 { 16 //It is also best practice to enclose graph changes in StartBatch and EndBatch calls 17 18 chart.DataSource.StartBatch(); 19 20 //It is best practice to clear a category before filing it with new data 21 chart.DataSource.ClearCategory("KOKO"); 22 chart.DataSource.AddPointToCategory("KOKO",0,0); 23 chart.DataSource.AddPointToCategory("KOKO", 1, 1); 24 chart.DataSource.AddPointToCategory("KOKO",2,3); 25 chart.DataSource.AddPointToCategory("KOKO", 5, 8); 26 27 ////now we do the same for the second category 28 //chart.DataSource.ClearCategory("Juhnko"); 29 //chart.DataSource.AddPointToCategory("KOKO", 0, 0); 30 //chart.DataSource.AddPointToCategory("KOKO", 5, 5); 31 //chart.DataSource.AddPointToCategory("KOKO", 8, 7); 32 //chart.DataSource.AddPointToCategory("KOKO", 15, 10); 33 34 //now we do the same for the three category 35 chart.DataSource.ClearCategory("liang"); 36 chart.DataSource.AddPointToCategory("liang", 0, 0); 37 chart.DataSource.AddPointToCategory("liang", 3, 3); 38 chart.DataSource.AddPointToCategory("liang", 5, 7); 39 chart.DataSource.AddPointToCategory("liang", 7, 11); 40 41 42 //each startBatch call must be matched with an EndBath call !!! 43 chart.DataSource.EndBatch(); 44 45 //graph is redrawn after EndBath is called 46 } 47 //lets handle a click event 48 public void OnItemClick(GraphChartBase.GraphEventArgs args) 49 { 50 Debug.Log("点击的类型是:"+args.Category+" 索引点为:"+args.Index); 51 } 52 53 54 55 // Update is called once per frame 56 void Update() 57 { 58 //now let's add a streaming data update the goes every 1 second. 59 Timer -= Time.deltaTime; 60 if (Timer<=0f) 61 { 62 Timer = 1f; 63 chart.DataSource.AddPointToCategory("KOKO",X, Random.value); 64 chart.DataSource.AddPointToCategory("liang", X, Random.value); 65 X++; 66 } 67 } 68 }