mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-24 18:00:26 +00:00
优化坐标绘制,支持大数据
This commit is contained in:
86
Demo/BarChartDemo.cs
Normal file
86
Demo/BarChartDemo.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using xcharts;
|
||||
|
||||
public class BarChartDemo : MonoBehaviour
|
||||
{
|
||||
public Theme theme = Theme.Dark;
|
||||
|
||||
private float time;
|
||||
private int count;
|
||||
private Theme checkTheme = Theme.Dark;
|
||||
|
||||
private int dataCount = 0;
|
||||
private BarChart bigdataChart;
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
var xchart = transform.Find("xchart");
|
||||
GridLayoutGroup grid = xchart.GetComponent<GridLayoutGroup>();
|
||||
RectTransform rect = transform.GetComponent<RectTransform>();
|
||||
var wid = rect.sizeDelta.x;
|
||||
int childNum = xchart.childCount;
|
||||
float hig = grid.padding.top + childNum * (grid.cellSize.y + grid.spacing.y);
|
||||
rect.sizeDelta = new Vector2(wid, hig);
|
||||
xchart.GetComponent<RectTransform>().sizeDelta = new Vector2(wid, hig);
|
||||
|
||||
bigdataChart = xchart.Find("barchart_bigdata").GetComponent<BarChart>();
|
||||
GenerateData(2000, bigdataChart);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
if (time >= 0)
|
||||
{
|
||||
time = 0;
|
||||
//count++;
|
||||
//bigdataChart.AddData(0, Random.Range(30, 120));
|
||||
//bigdataChart.AddXAxisCategory(count.ToString());
|
||||
//bigdataChart.InitXScale();
|
||||
//bigdataChart.RefreshChart();
|
||||
}
|
||||
if (checkTheme != theme)
|
||||
{
|
||||
checkTheme = theme;
|
||||
UpdateTheme(theme);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateTheme(Theme theme)
|
||||
{
|
||||
var charts = transform.Find("xchart").GetComponentsInChildren<BaseChart>();
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
chart.UpdateTheme(theme);
|
||||
}
|
||||
}
|
||||
|
||||
void GenerateData(int count,BarChart chart)
|
||||
{
|
||||
var baseValue = UnityEngine.Random.Range(0,1000);
|
||||
var time = new DateTime(2011, 1, 1);
|
||||
var smallBaseValue = 0;
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
chart.AddXAxisCategory(time.ToString("yyyy-MM-dd hh:mm:ss"));
|
||||
|
||||
smallBaseValue = i % 30 == 0
|
||||
? UnityEngine.Random.Range(0, 700)
|
||||
: (smallBaseValue + UnityEngine.Random.Range(0, 500) - 250);
|
||||
baseValue += UnityEngine.Random.Range(0, 20) - 10;
|
||||
//float value = Mathf.Max(
|
||||
// 0,
|
||||
// Mathf.Round(baseValue + smallBaseValue) + 3000
|
||||
//);
|
||||
var index = i % 100;
|
||||
var value = (Mathf.Sin(index / 5) * (index / 5 - 10) + index / 6) * 5;
|
||||
value = Mathf.Abs(value);
|
||||
chart.AddData(0, value);
|
||||
time = time.AddSeconds(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Demo/BarChartDemo.cs.meta
Normal file
13
Demo/BarChartDemo.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ba3595e8477b954888a5ad05e4368fe
|
||||
timeCreated: 1553643827
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
52
Demo/Demo.cs
Normal file
52
Demo/Demo.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using xcharts;
|
||||
|
||||
public class Demo : MonoBehaviour
|
||||
{
|
||||
public Theme theme = Theme.Dark;
|
||||
|
||||
private BaseChart chart;
|
||||
private float time;
|
||||
private int count;
|
||||
private Theme checkTheme = Theme.Dark;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
var xchart = transform.Find("xchart");
|
||||
GridLayoutGroup grid = xchart.GetComponent<GridLayoutGroup>();
|
||||
RectTransform rect = transform.GetComponent<RectTransform>();
|
||||
var wid = rect.sizeDelta.x;
|
||||
int childNum = xchart.childCount;
|
||||
float hig = grid.padding.top + childNum * (grid.cellSize.y + grid.spacing.y);
|
||||
rect.sizeDelta = new Vector2(wid, hig);
|
||||
xchart.GetComponent<RectTransform>().sizeDelta = new Vector2(wid, hig);
|
||||
|
||||
chart = xchart.gameObject.GetComponentInChildren<BaseChart>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
if (time >= 1)
|
||||
{
|
||||
time = 0;
|
||||
count++;
|
||||
chart.UpdateData(0, Random.RandomRange(60, 150));
|
||||
}
|
||||
if (checkTheme != theme)
|
||||
{
|
||||
checkTheme = theme;
|
||||
UpdateTheme(theme);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateTheme(Theme theme)
|
||||
{
|
||||
var charts = transform.Find("xchart").GetComponentsInChildren<BaseChart>();
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
chart.UpdateTheme(theme);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Demo/Demo.cs.meta
Normal file
13
Demo/Demo.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6bd57e81d68cac47a78ccb7a452c8d7
|
||||
timeCreated: 1536708123
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14829
Demo/demo.unity
Normal file
14829
Demo/demo.unity
Normal file
File diff suppressed because it is too large
Load Diff
9
Demo/demo.unity.meta
Normal file
9
Demo/demo.unity.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5b436c986812794a9b741314e4a43bd
|
||||
timeCreated: 1536101749
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
5307
Demo/demo_barchart.unity
Normal file
5307
Demo/demo_barchart.unity
Normal file
File diff suppressed because it is too large
Load Diff
9
Demo/demo_barchart.unity.meta
Normal file
9
Demo/demo_barchart.unity.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5adbd6df9174d6943b7eb8d23651ffd1
|
||||
timeCreated: 1553641950
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9221
Demo/demo_test.unity
Normal file
9221
Demo/demo_test.unity
Normal file
File diff suppressed because it is too large
Load Diff
9
Demo/demo_test.unity.meta
Normal file
9
Demo/demo_test.unity.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a142bb574d9f48c4fa8f0375629732e8
|
||||
timeCreated: 1539696983
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user