mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-16 21:40:41 +00:00
3.0
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -278,13 +277,21 @@ namespace XCharts.Example
|
||||
visualMap.range[0] = 0;
|
||||
visualMap.range[1] = 100;
|
||||
|
||||
var colors = new List<string>{"#313695", "#4575b4", "#74add1", "#abd9e9", "#e0f3f8", "#ffffbf",
|
||||
"#fee090", "#fdae61", "#f46d43", "#d73027", "#a50026"};
|
||||
visualMap.inRange.Clear();
|
||||
foreach (var str in colors)
|
||||
var colors = new List<string>
|
||||
{
|
||||
visualMap.inRange.Add(ThemeStyle.GetColor(str));
|
||||
}
|
||||
"#313695",
|
||||
"#4575b4",
|
||||
"#74add1",
|
||||
"#abd9e9",
|
||||
"#e0f3f8",
|
||||
"#ffffbf",
|
||||
"#fee090",
|
||||
"#fdae61",
|
||||
"#f46d43",
|
||||
"#d73027",
|
||||
"#a50026"
|
||||
};
|
||||
visualMap.AddColors(colors);
|
||||
var grid = chart.GetChartComponent<GridCoord>();
|
||||
grid.left = 80;
|
||||
grid.bottom = 100;
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using XCharts.Runtime;
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
using XCharts.Runtime;
|
||||
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Example
|
||||
{
|
||||
@@ -17,15 +15,11 @@ namespace XCharts.Example
|
||||
chart = gameObject.GetComponent<LineChart>();
|
||||
if (chart == null) return;
|
||||
|
||||
chart.onDraw = delegate (VertexHelper vh)
|
||||
{
|
||||
};
|
||||
chart.onDraw = delegate(VertexHelper vh) { };
|
||||
// or
|
||||
chart.onDrawBeforeSerie = delegate (VertexHelper vh, Serie serie)
|
||||
{
|
||||
};
|
||||
chart.onDrawBeforeSerie = delegate(VertexHelper vh, Serie serie) { };
|
||||
// or
|
||||
chart.onDrawAfterSerie = delegate (VertexHelper vh, Serie serie)
|
||||
chart.onDrawAfterSerie = delegate(VertexHelper vh, Serie serie)
|
||||
{
|
||||
if (serie.index != 0) return;
|
||||
var dataPoints = serie.context.dataPoints;
|
||||
@@ -41,9 +35,7 @@ namespace XCharts.Example
|
||||
}
|
||||
};
|
||||
// or
|
||||
chart.onDrawTop = delegate (VertexHelper vh)
|
||||
{
|
||||
};
|
||||
chart.onDrawTop = delegate(VertexHelper vh) { };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
@@ -8,21 +7,25 @@ namespace XCharts.Example
|
||||
[ExecuteInEditMode]
|
||||
public class Example13_LineSimple : MonoBehaviour
|
||||
{
|
||||
void Awake()
|
||||
{
|
||||
AddData();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
AddData();
|
||||
//OnTestBtn();
|
||||
}
|
||||
}
|
||||
|
||||
void AddData()
|
||||
{
|
||||
var chart = gameObject.GetComponent<LineChart>();
|
||||
var chart = gameObject.GetComponent<SimplifiedLineChart>();
|
||||
if (chart == null)
|
||||
{
|
||||
chart = gameObject.AddComponent<LineChart>();
|
||||
chart = gameObject.AddComponent<SimplifiedLineChart>();
|
||||
chart.Init();
|
||||
chart.SetSize(580, 300);
|
||||
}
|
||||
@@ -43,8 +46,8 @@ namespace XCharts.Example
|
||||
xAxis.boundaryGap = true;
|
||||
|
||||
chart.RemoveData();
|
||||
chart.AddSerie<Line>();
|
||||
chart.AddSerie<Line>();
|
||||
chart.AddSerie<SimplifiedLine>();
|
||||
chart.AddSerie<SimplifiedLine>();
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
chart.AddXAxisData("x" + i);
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
@@ -57,7 +56,7 @@ namespace XCharts.Example
|
||||
yAxis.minMaxType = Axis.AxisMinMaxType.Default;
|
||||
|
||||
chart.RemoveData();
|
||||
serie = chart.AddSerie<Bar>( "Bar1");
|
||||
serie = chart.AddSerie<Bar>("Bar1");
|
||||
|
||||
for (int i = 0; i < m_DataNum; i++)
|
||||
{
|
||||
@@ -67,7 +66,6 @@ namespace XCharts.Example
|
||||
yield return new WaitForSeconds(1);
|
||||
}
|
||||
|
||||
|
||||
IEnumerator BarMutilSerie()
|
||||
{
|
||||
chart.GetChartComponent<Title>().subText = "多条柱状图";
|
||||
@@ -80,7 +78,7 @@ namespace XCharts.Example
|
||||
yield return null;
|
||||
}
|
||||
|
||||
serie2 = chart.AddSerie<Bar>( "Bar2");
|
||||
serie2 = chart.AddSerie<Bar>("Bar2");
|
||||
serie2.lineType = LineType.Normal;
|
||||
serie2.barWidth = 0.35f;
|
||||
for (int i = 0; i < m_DataNum; i++)
|
||||
@@ -152,7 +150,7 @@ namespace XCharts.Example
|
||||
serie2.label.textStyle.color = Color.white;
|
||||
serie2.label.formatter = "{d:f0}%";
|
||||
serie2.labelDirty = true;
|
||||
|
||||
|
||||
chart.RefreshChart();
|
||||
yield return new WaitForSeconds(1);
|
||||
}
|
||||
46
Examples/Example21_BarRace.cs
Normal file
46
Examples/Example21_BarRace.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
namespace XCharts.Example
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class Example21_BarRace : MonoBehaviour
|
||||
{
|
||||
private BarChart chart;
|
||||
private float lastTime;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
chart = gameObject.GetComponent<BarChart>();
|
||||
chart.ClearData();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
chart.AddYAxisData("y" + i);
|
||||
chart.AddData(0, Random.Range(0, 200));
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Time.time - lastTime >= 3f)
|
||||
{
|
||||
lastTime = Time.time;
|
||||
UpdateData();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateData()
|
||||
{
|
||||
var serie = chart.GetSerie(0);
|
||||
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
if (Random.Range(0, 1f) > 0.9f)
|
||||
chart.UpdateData(0, i, chart.GetData(0, i) + Mathf.Round(Random.Range(0, 2000)));
|
||||
else
|
||||
chart.UpdateData(0, i, chart.GetData(0, i) + Mathf.Round(Random.Range(0, 200)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Examples/Example21_BarRace.cs.meta
Normal file
11
Examples/Example21_BarRace.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9842ca7fe07044666950b6f53ef65fdb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
@@ -73,7 +72,7 @@ namespace XCharts.Example
|
||||
chart.AddData(0, 135, "视频广告");
|
||||
chart.AddData(0, 1548, "搜索引擎");
|
||||
|
||||
chart.onPointerClickPie = delegate (PointerEventData e, int serieIndex, int dataIndex)
|
||||
chart.onPointerClickPie = delegate(PointerEventData e, int serieIndex, int dataIndex)
|
||||
{
|
||||
|
||||
};
|
||||
@@ -118,12 +117,12 @@ namespace XCharts.Example
|
||||
chart.RefreshChart();
|
||||
yield return new WaitForSeconds(1);
|
||||
|
||||
serie.data[0].GetOrAddComponent<SerieDataBaseInfo>().selected = true;
|
||||
serie.data[0].selected = true;
|
||||
chart.RefreshChart();
|
||||
yield return new WaitForSeconds(1);
|
||||
|
||||
serie.gap = 0f;
|
||||
serie.data[0].GetOrAddComponent<SerieDataBaseInfo>().selected = false;
|
||||
serie.data[0].selected = false;
|
||||
chart.RefreshChart();
|
||||
yield return new WaitForSeconds(1);
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -25,12 +24,12 @@ namespace XCharts.Example
|
||||
|
||||
float SymbolSize(List<double> data)
|
||||
{
|
||||
return (float)(Math.Sqrt(data[2]) / 6e2);
|
||||
return (float) (Math.Sqrt(data[2]) / 6e2);
|
||||
}
|
||||
|
||||
float SymbolSelectedSize(List<double> data)
|
||||
{
|
||||
return (float)(Math.Sqrt(data[2]) / 5e2);
|
||||
return (float) (Math.Sqrt(data[2]) / 5e2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
@@ -48,11 +47,10 @@ namespace XCharts.Example
|
||||
serie.itemStyle.borderColor = Color.clear;
|
||||
|
||||
//设置高亮样式
|
||||
serie.AddExtraComponent<Emphasis>();
|
||||
serie.emphasis.show = true;
|
||||
serie.emphasis.itemStyle.show = true;
|
||||
serie.emphasis.itemStyle.borderWidth = 1;
|
||||
serie.emphasis.itemStyle.borderColor = Color.black;
|
||||
serie.AddExtraComponent<EmphasisItemStyle>();
|
||||
serie.emphasisItemStyle.show = true;
|
||||
serie.emphasisItemStyle.borderWidth = 1;
|
||||
serie.emphasisItemStyle.borderColor = Color.black;
|
||||
|
||||
//设置视觉映射组件
|
||||
var visualMap = chart.GetChartComponent<VisualMap>();
|
||||
@@ -66,17 +64,25 @@ namespace XCharts.Example
|
||||
visualMap.location.left = 30;
|
||||
|
||||
//清空颜色重新添加
|
||||
visualMap.inRange.Clear();
|
||||
|
||||
var heatmapGridWid = 10f;
|
||||
int xSplitNumber = (int)(grid.context.width / heatmapGridWid);
|
||||
int ySplitNumber = (int)(grid.context.height / heatmapGridWid);
|
||||
var colors = new List<string>{"#313695", "#4575b4", "#74add1", "#abd9e9", "#e0f3f8", "#ffffbf",
|
||||
"#fee090", "#fdae61", "#f46d43", "#d73027", "#a50026"};
|
||||
foreach (var str in colors)
|
||||
int xSplitNumber = (int) (grid.context.width / heatmapGridWid);
|
||||
int ySplitNumber = (int) (grid.context.height / heatmapGridWid);
|
||||
var colors = new List<string>
|
||||
{
|
||||
visualMap.inRange.Add(ThemeStyle.GetColor(str));
|
||||
}
|
||||
"#313695",
|
||||
"#4575b4",
|
||||
"#74add1",
|
||||
"#abd9e9",
|
||||
"#e0f3f8",
|
||||
"#ffffbf",
|
||||
"#fee090",
|
||||
"#fdae61",
|
||||
"#f46d43",
|
||||
"#d73027",
|
||||
"#a50026"
|
||||
};
|
||||
visualMap.AddColors(colors);
|
||||
//添加xAxis的数据
|
||||
for (int i = 0; i < xSplitNumber; i++)
|
||||
{
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
@@ -31,9 +29,7 @@ namespace XCharts.Example
|
||||
}
|
||||
}
|
||||
|
||||
void AddData()
|
||||
{
|
||||
}
|
||||
void AddData() { }
|
||||
|
||||
void GenerateOHLC(int count)
|
||||
{
|
||||
@@ -46,15 +42,17 @@ namespace XCharts.Example
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
baseValue = baseValue + Random.Range(0f,1f) * 30 - 10;
|
||||
for(int j=0;j< 4;j++){
|
||||
boxVals[j] = (Random.Range(0f,1f) - 0.5f) * dayRange + baseValue;
|
||||
baseValue = baseValue + Random.Range(0f, 1f) * 30 - 10;
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
boxVals[j] = (Random.Range(0f, 1f) - 0.5f) * dayRange + baseValue;
|
||||
}
|
||||
System.Array.Sort(boxVals);
|
||||
var openIdx = Mathf.RoundToInt(Random.Range(0f,1f) * 3);
|
||||
var closeIdx = Mathf.RoundToInt(Random.Range(0f,1f) * 2);
|
||||
if(openIdx == closeIdx){
|
||||
closeIdx ++;
|
||||
var openIdx = Mathf.RoundToInt(Random.Range(0f, 1f) * 3);
|
||||
var closeIdx = Mathf.RoundToInt(Random.Range(0f, 1f) * 2);
|
||||
if (openIdx == closeIdx)
|
||||
{
|
||||
closeIdx++;
|
||||
}
|
||||
//var volumn = boxVals[3]*(1000+Random.Range(0f,1f) * 500);
|
||||
var open = boxVals[openIdx];
|
||||
@@ -63,7 +61,7 @@ namespace XCharts.Example
|
||||
var heighest = boxVals[3];
|
||||
|
||||
chart.AddXAxisData(i.ToString());
|
||||
chart.AddData(0,open,close,lowest,heighest);
|
||||
chart.AddData(0, open, close, lowest, heighest);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
@@ -28,9 +27,7 @@ namespace XCharts.Example
|
||||
label.offset = new Vector3(0, 20, 0);
|
||||
|
||||
var serieData = chart.AddData(0, 20);
|
||||
//var serieData = serie1.GetSerieData(0);
|
||||
var baseInfo = serieData.GetOrAddComponent<SerieDataBaseInfo>();
|
||||
baseInfo.radius = 10;
|
||||
serieData.radius = 10;
|
||||
var itemStyle = serieData.GetOrAddComponent<ItemStyle>();
|
||||
itemStyle.color = Color.blue;
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
@@ -12,7 +11,7 @@ namespace XCharts.Example
|
||||
{
|
||||
public int maxCacheDataNumber = 100;
|
||||
public float initDataTime = 2;
|
||||
public bool insertDataToHead = false;
|
||||
public bool insertDataToHead = true;
|
||||
|
||||
private BaseChart chart;
|
||||
private float updateTime;
|
||||
@@ -42,7 +41,7 @@ namespace XCharts.Example
|
||||
{
|
||||
if (initCount < maxCacheDataNumber)
|
||||
{
|
||||
int count = (int)(maxCacheDataNumber / initDataTime * Time.deltaTime);
|
||||
int count = (int) (maxCacheDataNumber / initDataTime * Time.deltaTime);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
timeNow = timeNow.AddSeconds(1);
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XCharts.Runtime;
|
||||
@@ -31,21 +30,22 @@ namespace XCharts.Example
|
||||
|
||||
void OnTestBtn()
|
||||
{
|
||||
object[][] m_TestData = new object[][]{
|
||||
new object[]{"01/06/20", 2.2d, 5.6d},
|
||||
new object[]{"22/06/20", 2.4d, 5.3d},
|
||||
new object[]{"04/08/21", 4.5d, 5.4d},
|
||||
new object[]{"05/08/21", 6.3d, 6.4d},
|
||||
new object[]{"06/08/21", 3.1d, 6.4d},
|
||||
new object[]{"09/08/21", 3.9d, 6.3d},
|
||||
new object[]{"10/08/21", 1.9d, 4.6d},
|
||||
object[][] m_TestData = new object[][]
|
||||
{
|
||||
new object[] { "01/06/20", 2.2d, 5.6d },
|
||||
new object[] { "22/06/20", 2.4d, 5.3d },
|
||||
new object[] { "04/08/21", 4.5d, 5.4d },
|
||||
new object[] { "05/08/21", 6.3d, 6.4d },
|
||||
new object[] { "06/08/21", 3.1d, 6.4d },
|
||||
new object[] { "09/08/21", 3.9d, 6.3d },
|
||||
new object[] { "10/08/21", 1.9d, 4.6d },
|
||||
};
|
||||
chart.ClearData();
|
||||
foreach (var list in m_TestData)
|
||||
{
|
||||
chart.AddXAxisData((string)list[0]);
|
||||
chart.AddData(0, (double)list[1]);
|
||||
chart.AddData(1, (double)list[2]);
|
||||
chart.AddXAxisData((string) list[0]);
|
||||
chart.AddData(0, (double) list[1]);
|
||||
chart.AddData(1, (double) list[2]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using UnityEngine;
|
||||
using XCharts.Runtime;
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f67670c9ee0e64262950aaf07562454e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user