69 lines
1.7 KiB
C#
69 lines
1.7 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using System;
|
|||
|
|
using System.Linq.Expressions;
|
|||
|
|
using BarGraph.VittorCloud;
|
|||
|
|
|
|||
|
|
public class BarGraphExample : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
public List<BarGraphDataSet> exampleDataSet; // public data set for inserting data into the bar graph
|
|||
|
|
BarGraphGenerator barGraphGenerator;
|
|||
|
|
|
|||
|
|
void Start()
|
|||
|
|
{
|
|||
|
|
barGraphGenerator = GetComponent<BarGraphGenerator>();
|
|||
|
|
|
|||
|
|
|
|||
|
|
//if the exampleDataSet list is empty then return.
|
|||
|
|
if (exampleDataSet.Count == 0)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Debug.LogError("ExampleDataSet is Empty!");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
barGraphGenerator.GeneratBarGraph(exampleDataSet);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
//call when the graph starting animation completed, for updating the data on run time
|
|||
|
|
public void StartUpdatingGraph()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
|
|||
|
|
StartCoroutine(CreateDataSet());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
IEnumerator CreateDataSet()
|
|||
|
|
{
|
|||
|
|
// yield return new WaitForSeconds(3.0f);
|
|||
|
|
while (true)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
GenerateRandomData();
|
|||
|
|
|
|||
|
|
yield return new WaitForSeconds(2.0f);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
//Generates the random data for the created bars
|
|||
|
|
void GenerateRandomData()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
int dataSetIndex = UnityEngine.Random.Range(0, exampleDataSet.Count);
|
|||
|
|
int xyValueIndex = UnityEngine.Random.Range(0, exampleDataSet[dataSetIndex].ListOfBars.Count);
|
|||
|
|
exampleDataSet[dataSetIndex].ListOfBars[xyValueIndex].YValue = UnityEngine.Random.Range(barGraphGenerator.yMinValue, barGraphGenerator.yMaxValue);
|
|||
|
|
barGraphGenerator.AddNewDataSet(dataSetIndex, xyValueIndex, exampleDataSet[dataSetIndex].ListOfBars[xyValueIndex].YValue);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|