mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 15:00:08 +00:00
优化坐标绘制,支持大数据
This commit is contained in:
10
Demo.meta
Normal file
10
Demo.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e6b0fb015bc6524d8bab146b6f2ba3a
|
||||
folderAsset: yes
|
||||
timeCreated: 1553641866
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
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:
|
||||
@@ -31,7 +31,7 @@ namespace xcharts
|
||||
if (yAxis.type == AxisType.category)
|
||||
{
|
||||
int seriesCount = seriesList.Count;
|
||||
float scaleWid = coordinateHig / (yAxis.splitNumber - 1);
|
||||
float scaleWid = yAxis.GetSplitWidth(coordinateHig);
|
||||
float barWid = barInfo.barWid > 1 ? barInfo.barWid : scaleWid * barInfo.barWid;
|
||||
float offset = (scaleWid - barWid * seriesCount - barInfo.space * (seriesCount - 1)) / 2;
|
||||
float max = GetMaxValue();
|
||||
@@ -59,7 +59,7 @@ namespace xcharts
|
||||
{
|
||||
float data = series.dataList[i];
|
||||
float pX = zeroX + coordinate.tickness;
|
||||
float pY = zeroY + i * coordinateHig / (yAxis.splitNumber - 1);
|
||||
float pY = zeroY + i * scaleWid;
|
||||
if (!yAxis.boundaryGap) pY -= scaleWid / 2;
|
||||
float barHig = data / max * coordinateWid;
|
||||
float space = offset + j * (barWid + barInfo.space);
|
||||
@@ -74,7 +74,7 @@ namespace xcharts
|
||||
else
|
||||
{
|
||||
int seriesCount = seriesList.Count;
|
||||
float scaleWid = coordinateWid / (xAxis.splitNumber - 1);
|
||||
float scaleWid = xAxis.GetDataWidth(coordinateWid);
|
||||
float barWid = barInfo.barWid > 1 ? barInfo.barWid : scaleWid * barInfo.barWid;
|
||||
float offset = (scaleWid - barWid * seriesCount - barInfo.space * (seriesCount - 1)) / 2;
|
||||
float max = GetMaxValue();
|
||||
@@ -101,7 +101,7 @@ namespace xcharts
|
||||
for (int i = startIndex; i < series.dataList.Count; i++)
|
||||
{
|
||||
float data = series.dataList[i];
|
||||
float pX = zeroX + i * coordinateWid / (xAxis.splitNumber - 1);
|
||||
float pX = zeroX + i * scaleWid;
|
||||
if (!xAxis.boundaryGap) pX -= scaleWid / 2;
|
||||
float pY = zeroY + coordinate.tickness;
|
||||
float barHig = data / max * coordinateHig;
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace xcharts
|
||||
public bool boundaryGap = true;
|
||||
public List<string> data;
|
||||
|
||||
public void AddCategory(string category)
|
||||
public void AddData(string category)
|
||||
{
|
||||
if (data.Count >= maxSplitNumber && maxSplitNumber != 0)
|
||||
{
|
||||
@@ -54,6 +54,58 @@ namespace xcharts
|
||||
}
|
||||
data.Add(category);
|
||||
}
|
||||
|
||||
public string GetData(int index,float maxData = 0)
|
||||
{
|
||||
if(type == AxisType.value)
|
||||
{
|
||||
return ((int)(maxData * index / GetSplitNumber())).ToString();
|
||||
}
|
||||
int dataCount = data.Count;
|
||||
if (dataCount <= 0) return "";
|
||||
float rate = dataCount / GetScaleNumber();
|
||||
if (rate < 1) rate = 1;
|
||||
int newIndex = (int)(index * rate >= dataCount - 1 ? dataCount - 1 : index * rate);
|
||||
return data[newIndex];
|
||||
}
|
||||
|
||||
public int GetSplitNumber()
|
||||
{
|
||||
if (data.Count > 2 * splitNumber || data.Count <= 0)
|
||||
return splitNumber;
|
||||
else
|
||||
return data.Count;
|
||||
}
|
||||
|
||||
public float GetSplitWidth(float coordinateWidth)
|
||||
{
|
||||
return coordinateWidth / (boundaryGap ? GetSplitNumber(): GetSplitNumber() - 1);
|
||||
}
|
||||
|
||||
public int GetDataNumber()
|
||||
{
|
||||
return data.Count;
|
||||
}
|
||||
|
||||
public float GetDataWidth(float coordinateWidth)
|
||||
{
|
||||
return coordinateWidth / (boundaryGap ? data.Count : data.Count - 1);
|
||||
}
|
||||
|
||||
public int GetScaleNumber()
|
||||
{
|
||||
if (data.Count > 2 * splitNumber || data.Count <= 0)
|
||||
return boundaryGap ? splitNumber + 1 : splitNumber;
|
||||
else
|
||||
return boundaryGap ? data.Count + 1 : data.Count;
|
||||
}
|
||||
|
||||
public float GetScaleWidth(float coordinateWidth)
|
||||
{
|
||||
int num = GetScaleNumber() - 1;
|
||||
if (num <= 0) num = 1;
|
||||
return coordinateWidth / num;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
@@ -133,8 +185,8 @@ namespace xcharts
|
||||
{
|
||||
if (xAxis.type == AxisType.value)
|
||||
{
|
||||
float splitWid = coordinateHig / (yAxis.splitNumber - 1);
|
||||
for (int i = 0; i < yAxis.splitNumber; i++)
|
||||
float splitWid =yAxis.GetDataWidth(coordinateHig);
|
||||
for (int i = 0; i < yAxis.GetDataNumber(); i++)
|
||||
{
|
||||
float pY = zeroY + i * splitWid;
|
||||
if (yAxis.boundaryGap)
|
||||
@@ -157,8 +209,8 @@ namespace xcharts
|
||||
}
|
||||
else
|
||||
{
|
||||
float splitWid = coordinateWid / (xAxis.splitNumber - 1);
|
||||
for (int i = 0; i < xAxis.splitNumber; i++)
|
||||
float splitWid =xAxis.GetDataWidth(coordinateWid);
|
||||
for (int i = 0; i < xAxis.GetDataNumber(); i++)
|
||||
{
|
||||
float pX = zeroX + i * splitWid;
|
||||
if (xAxis.boundaryGap)
|
||||
@@ -196,20 +248,20 @@ namespace xcharts
|
||||
{
|
||||
base.RefreshTooltip();
|
||||
int index = tooltip.DataIndex - 1;
|
||||
if (index < 0)
|
||||
{
|
||||
tooltip.SetActive(false);
|
||||
return;
|
||||
}
|
||||
Axis tempAxis = xAxis.type == AxisType.value ? (Axis)yAxis : (Axis)xAxis;
|
||||
if (index > tempAxis.data.Count - 1)
|
||||
{
|
||||
index = tempAxis.data.Count - 1;
|
||||
}
|
||||
if (index < 0)
|
||||
{
|
||||
tooltip.SetActive(false);
|
||||
return;
|
||||
}
|
||||
tooltip.SetActive(true);
|
||||
if (seriesList.Count == 1)
|
||||
{
|
||||
string txt = tempAxis.data[index] + ": " + seriesList[0].dataList[index];
|
||||
string txt = tempAxis.GetData(index) + ": " + seriesList[0].dataList[index];
|
||||
tooltip.UpdateTooltipText(txt);
|
||||
}
|
||||
else
|
||||
@@ -271,136 +323,77 @@ namespace xcharts
|
||||
|
||||
public void AddXAxisCategory(string category)
|
||||
{
|
||||
xAxis.AddCategory(category);
|
||||
xAxis.AddData(category);
|
||||
OnXAxisChanged();
|
||||
}
|
||||
|
||||
public void AddYAxisCategory(string category)
|
||||
{
|
||||
yAxis.AddCategory(category);
|
||||
yAxis.AddData(category);
|
||||
OnYAxisChanged();
|
||||
}
|
||||
|
||||
private void InitYScale()
|
||||
{
|
||||
yScaleTextList.Clear();
|
||||
if (yAxis.type == AxisType.value)
|
||||
float max = GetMaxValue();
|
||||
float scaleWid = yAxis.GetScaleWidth(coordinateHig);
|
||||
for (int i = 0; i < yAxis.GetSplitNumber(); i++)
|
||||
{
|
||||
float max = GetMaxValue();
|
||||
if (max <= 0) max = 400;
|
||||
yAxis.splitNumber = DEFAULT_YSACLE_NUM;
|
||||
for (int i = 0; i < yAxis.splitNumber; i++)
|
||||
{
|
||||
Text txt = ChartUtils.AddTextObject(YSCALE_TEXT_PREFIX + i, transform, themeInfo.font,
|
||||
Text txt = ChartUtils.AddTextObject(YSCALE_TEXT_PREFIX + i, transform, themeInfo.font,
|
||||
themeInfo.textColor, TextAnchor.MiddleRight, Vector2.zero, Vector2.zero,
|
||||
new Vector2(1, 0.5f),
|
||||
new Vector2(coordinate.left, 20));
|
||||
txt.transform.localPosition = GetYScalePosition(i);
|
||||
txt.text = ((int)(max * i / yAxis.splitNumber)).ToString();
|
||||
txt.gameObject.SetActive(coordinate.show);
|
||||
yScaleTextList.Add(txt);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
yAxis.splitNumber = yAxis.boundaryGap ? yAxis.data.Count + 1 : yAxis.data.Count;
|
||||
for (int i = 0; i < yAxis.data.Count; i++)
|
||||
{
|
||||
Text txt = ChartUtils.AddTextObject(YSCALE_TEXT_PREFIX + i, transform, themeInfo.font,
|
||||
themeInfo.textColor, TextAnchor.MiddleRight, Vector2.zero, Vector2.zero,
|
||||
new Vector2(1, 0.5f),
|
||||
new Vector2(coordinate.left, 20));
|
||||
txt.transform.localPosition = GetYScalePosition(i);
|
||||
txt.text = yAxis.data[i];
|
||||
txt.gameObject.SetActive(coordinate.show);
|
||||
yScaleTextList.Add(txt);
|
||||
}
|
||||
txt.transform.localPosition = GetYScalePosition(scaleWid, i);
|
||||
txt.text = yAxis.GetData(i, max);
|
||||
txt.gameObject.SetActive(coordinate.show);
|
||||
yScaleTextList.Add(txt);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitXScale()
|
||||
public void InitXScale()
|
||||
{
|
||||
xScaleTextList.Clear();
|
||||
if (xAxis.type == AxisType.value)
|
||||
float max = GetMaxValue();
|
||||
float scaleWid = xAxis.GetScaleWidth(coordinateWid);
|
||||
for (int i = 0; i < xAxis.GetSplitNumber(); i++)
|
||||
{
|
||||
float max = GetMaxValue();
|
||||
if (max <= 0) max = 400;
|
||||
xAxis.splitNumber = DEFAULT_YSACLE_NUM;
|
||||
float scaleWid = coordinateWid / (xAxis.splitNumber - 1);
|
||||
for (int i = 0; i < xAxis.splitNumber; i++)
|
||||
{
|
||||
Text txt = ChartUtils.AddTextObject(XSCALE_TEXT_PREFIX + i, transform, themeInfo.font,
|
||||
themeInfo.textColor, TextAnchor.MiddleCenter, Vector2.zero, Vector2.zero,
|
||||
new Vector2(1, 0.5f),
|
||||
new Vector2(scaleWid, 20));
|
||||
txt.transform.localPosition = GetXScalePosition(i);
|
||||
txt.text = ((int)(max * i / xAxis.splitNumber)).ToString();
|
||||
txt.gameObject.SetActive(coordinate.show);
|
||||
xScaleTextList.Add(txt);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xAxis.splitNumber = xAxis.boundaryGap ? xAxis.data.Count + 1 : xAxis.data.Count;
|
||||
float scaleWid = coordinateWid / (xAxis.data.Count - 1);
|
||||
for (int i = 0; i < xAxis.data.Count; i++)
|
||||
{
|
||||
Text txt = ChartUtils.AddTextObject(XSCALE_TEXT_PREFIX + i, transform, themeInfo.font,
|
||||
themeInfo.textColor, TextAnchor.MiddleCenter, Vector2.zero, Vector2.zero,
|
||||
new Vector2(1, 0.5f),
|
||||
new Vector2(scaleWid, 20));
|
||||
txt.transform.localPosition = GetXScalePosition(i);
|
||||
txt.text = xAxis.data[i];
|
||||
txt.gameObject.SetActive(coordinate.show);
|
||||
xScaleTextList.Add(txt);
|
||||
}
|
||||
Text txt = ChartUtils.AddTextObject(XSCALE_TEXT_PREFIX + i, transform, themeInfo.font,
|
||||
themeInfo.textColor, TextAnchor.MiddleCenter, Vector2.zero, Vector2.zero,
|
||||
new Vector2(1, 0.5f),
|
||||
new Vector2(scaleWid, 20));
|
||||
txt.transform.localPosition = GetXScalePosition(scaleWid, i);
|
||||
txt.text = xAxis.GetData(i, max);
|
||||
txt.gameObject.SetActive(coordinate.show);
|
||||
xScaleTextList.Add(txt);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 GetYScalePosition(int i)
|
||||
private Vector3 GetYScalePosition(float scaleWid,int i)
|
||||
{
|
||||
float scaleWid = coordinateHig / (yAxis.splitNumber - 1);
|
||||
if (yAxis.type == AxisType.value)
|
||||
if (yAxis.boundaryGap)
|
||||
{
|
||||
return new Vector3(zeroX - coordinate.splitWidth - 2f,
|
||||
zeroY + i * scaleWid, 0);
|
||||
zeroY + (i + 0.5f) * scaleWid, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yAxis.boundaryGap)
|
||||
{
|
||||
return new Vector3(zeroX - coordinate.splitWidth - 2f,
|
||||
zeroY + (i + 0.5f) * scaleWid, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Vector3(zeroX - coordinate.splitWidth - 2f,
|
||||
zeroY + i * scaleWid, 0);
|
||||
}
|
||||
|
||||
return new Vector3(zeroX - coordinate.splitWidth - 2f,
|
||||
zeroY + i * scaleWid, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 GetXScalePosition(int i)
|
||||
private Vector3 GetXScalePosition(float scaleWid,int i)
|
||||
{
|
||||
float scaleWid = coordinateWid / (xAxis.splitNumber - 1);
|
||||
if (xAxis.type == AxisType.value)
|
||||
if (xAxis.boundaryGap)
|
||||
{
|
||||
return new Vector3(zeroX + (i + 1) * scaleWid, zeroY - coordinate.splitWidth - 5, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Vector3(zeroX + (i + 1 - 0.5f) * scaleWid,
|
||||
zeroY - coordinate.splitWidth - 10, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xAxis.boundaryGap)
|
||||
{
|
||||
return new Vector3(zeroX + (i + 1) * scaleWid, zeroY - coordinate.splitWidth - 5, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Vector3(zeroX + (i + 1 - 0.5f) * scaleWid,
|
||||
zeroY - coordinate.splitWidth - 5, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckCoordinate()
|
||||
@@ -478,18 +471,20 @@ namespace xcharts
|
||||
protected virtual void OnCoordinateSize()
|
||||
{
|
||||
//update yScale pos
|
||||
for (int i = 0; i < yAxis.splitNumber; i++)
|
||||
float yscaleWid = coordinateHig / (yAxis.GetSplitNumber() - 1);
|
||||
float xscaleWid = coordinateHig / (xAxis.GetSplitNumber() - 1);
|
||||
for (int i = 0; i < yAxis.GetSplitNumber(); i++)
|
||||
{
|
||||
if (i < yScaleTextList.Count && yScaleTextList[i])
|
||||
{
|
||||
yScaleTextList[i].transform.localPosition = GetYScalePosition(i);
|
||||
yScaleTextList[i].transform.localPosition = GetYScalePosition(yscaleWid,i);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < xAxis.splitNumber; i++)
|
||||
for (int i = 0; i < xAxis.GetSplitNumber(); i++)
|
||||
{
|
||||
if (i < xScaleTextList.Count && xScaleTextList[i])
|
||||
{
|
||||
xScaleTextList[i].transform.localPosition = GetXScalePosition(i);
|
||||
xScaleTextList[i].transform.localPosition = GetXScalePosition(xscaleWid, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -528,10 +523,10 @@ namespace xcharts
|
||||
{
|
||||
if (!coordinate.show) return;
|
||||
// draw splitline
|
||||
for (int i = 1; i < yAxis.splitNumber; i++)
|
||||
for (int i = 1; i < yAxis.GetScaleNumber(); i++)
|
||||
{
|
||||
float pX = zeroX - coordinate.splitWidth;
|
||||
float pY = zeroY + i * coordinateHig / (yAxis.splitNumber - 1);
|
||||
float pY = zeroY + i * coordinateHig / (yAxis.GetScaleNumber() - 1);
|
||||
ChartUtils.DrawLine(vh, new Vector3(pX, pY), new Vector3(zeroX, pY), coordinate.tickness,
|
||||
themeInfo.axisLineColor);
|
||||
if (yAxis.showSplitLine)
|
||||
@@ -540,9 +535,9 @@ namespace xcharts
|
||||
new Vector3(zeroX + coordinateWid, pY));
|
||||
}
|
||||
}
|
||||
for (int i = 1; i < xAxis.splitNumber; i++)
|
||||
for (int i = 1; i < xAxis.GetScaleNumber(); i++)
|
||||
{
|
||||
float pX = zeroX + i * coordinateWid / (xAxis.splitNumber - 1);
|
||||
float pX = zeroX + i * coordinateWid / (xAxis.GetScaleNumber() - 1);
|
||||
float pY = zeroY - coordinate.splitWidth - 2;
|
||||
ChartUtils.DrawLine(vh, new Vector3(pX, zeroY), new Vector3(pX, pY), coordinate.tickness,
|
||||
themeInfo.axisLineColor);
|
||||
|
||||
@@ -295,6 +295,11 @@ namespace xcharts
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public void AddData(int legend,float value)
|
||||
{
|
||||
seriesList[legend].AddData(value);
|
||||
}
|
||||
|
||||
public void UpdateData(string legend, float value, int dataIndex = 0)
|
||||
{
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
@@ -596,7 +601,7 @@ namespace xcharts
|
||||
{
|
||||
}
|
||||
|
||||
protected void RefreshChart()
|
||||
public void RefreshChart()
|
||||
{
|
||||
int tempWid = (int)chartWid;
|
||||
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, tempWid - 1);
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace xcharts
|
||||
base.DrawChart(vh);
|
||||
int seriesCount = seriesList.Count;
|
||||
float max = GetMaxValue();
|
||||
float scaleWid = coordinateWid / (xAxis.splitNumber - 1);
|
||||
float scaleWid = xAxis.GetSplitWidth(coordinateWid);
|
||||
for (int j = 0; j < seriesCount; j++)
|
||||
{
|
||||
if (!legend.IsShowSeries(j)) continue;
|
||||
@@ -122,7 +122,7 @@ namespace xcharts
|
||||
//draw tooltip line
|
||||
if (tooltip.show && tooltip.DataIndex > 0)
|
||||
{
|
||||
float splitWid = coordinateWid / (xAxis.splitNumber - 1);
|
||||
float splitWid = coordinateWid / (xAxis.GetSplitNumber() - 1);
|
||||
float px = zeroX + (tooltip.DataIndex - 1) * splitWid + (xAxis.boundaryGap ? splitWid / 2 : 0);
|
||||
Vector2 sp = new Vector2(px, zeroY);
|
||||
Vector2 ep = new Vector2(px, zeroY + coordinateHig);
|
||||
|
||||
Reference in New Issue
Block a user