mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 18:30:14 +00:00
增加数据更新接口UpdateData
This commit is contained in:
@@ -28,7 +28,7 @@ namespace xcharts
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
{
|
||||
base.DrawChart(vh);
|
||||
if(yAxis.type == AxisType.category)
|
||||
if (yAxis.type == AxisType.category)
|
||||
{
|
||||
int seriesCount = seriesList.Count;
|
||||
float scaleWid = coordinateHig / (yAxis.splitNumber - 1);
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace xcharts
|
||||
else
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(tempAxis.data[index]);
|
||||
for(int i=0; i<seriesList.Count;i++)
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
string strColor = ColorUtility.ToHtmlStringRGBA(themeInfo.GetColor(i));
|
||||
string key = seriesList[i].name;
|
||||
@@ -292,7 +292,7 @@ namespace xcharts
|
||||
for (int i = 0; i < yAxis.splitNumber; i++)
|
||||
{
|
||||
Text txt = ChartUtils.AddTextObject(YSCALE_TEXT_PREFIX + i, transform, themeInfo.font,
|
||||
themeInfo.textColor, TextAnchor.MiddleRight, Vector2.zero, Vector2.zero,
|
||||
themeInfo.textColor, TextAnchor.MiddleRight, Vector2.zero, Vector2.zero,
|
||||
new Vector2(1, 0.5f),
|
||||
new Vector2(coordinate.left, 20));
|
||||
txt.transform.localPosition = GetYScalePosition(i);
|
||||
@@ -536,7 +536,7 @@ namespace xcharts
|
||||
themeInfo.axisLineColor);
|
||||
if (yAxis.showSplitLine)
|
||||
{
|
||||
DrawSplitLine(vh, true,yAxis.splitLineType, new Vector3(zeroX, pY),
|
||||
DrawSplitLine(vh, true, yAxis.splitLineType, new Vector3(zeroX, pY),
|
||||
new Vector3(zeroX + coordinateWid, pY));
|
||||
}
|
||||
}
|
||||
@@ -548,20 +548,20 @@ namespace xcharts
|
||||
themeInfo.axisLineColor);
|
||||
if (xAxis.showSplitLine)
|
||||
{
|
||||
DrawSplitLine(vh, false,xAxis.splitLineType, new Vector3(pX, zeroY),
|
||||
DrawSplitLine(vh, false, xAxis.splitLineType, new Vector3(pX, zeroY),
|
||||
new Vector3(pX, zeroY + coordinateHig));
|
||||
}
|
||||
}
|
||||
//draw x,y axis
|
||||
ChartUtils.DrawLine(vh, new Vector3(zeroX, zeroY - coordinate.splitWidth),
|
||||
new Vector3(zeroX, zeroY + coordinateHig + 2), coordinate.tickness,
|
||||
new Vector3(zeroX, zeroY + coordinateHig + 2), coordinate.tickness,
|
||||
themeInfo.axisLineColor);
|
||||
ChartUtils.DrawLine(vh, new Vector3(zeroX - coordinate.splitWidth, zeroY),
|
||||
new Vector3(zeroX + coordinateWid + 2, zeroY), coordinate.tickness,
|
||||
new Vector3(zeroX + coordinateWid + 2, zeroY), coordinate.tickness,
|
||||
themeInfo.axisLineColor);
|
||||
}
|
||||
|
||||
private void DrawSplitLine(VertexHelper vh,bool isYAxis,SplitLineType type,Vector3 startPos,
|
||||
private void DrawSplitLine(VertexHelper vh, bool isYAxis, SplitLineType type, Vector3 startPos,
|
||||
Vector3 endPos)
|
||||
{
|
||||
switch (type)
|
||||
@@ -571,7 +571,7 @@ namespace xcharts
|
||||
var startX = startPos.x;
|
||||
var startY = startPos.y;
|
||||
var dashLen = type == SplitLineType.dashed ? 6 : 2.5f;
|
||||
var count = isYAxis ? (endPos.x - startPos.x) / (dashLen * 2):
|
||||
var count = isYAxis ? (endPos.x - startPos.x) / (dashLen * 2) :
|
||||
(endPos.y - startPos.y) / (dashLen * 2);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
@@ -589,7 +589,7 @@ namespace xcharts
|
||||
coordinate.tickness, themeInfo.axisSplitLineColor);
|
||||
startY += dashLen * 2;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
case SplitLineType.solid:
|
||||
|
||||
@@ -76,12 +76,12 @@ namespace xcharts
|
||||
}
|
||||
}
|
||||
|
||||
public void SetShowData(int index,bool flag)
|
||||
public void SetShowData(int index, bool flag)
|
||||
{
|
||||
dataShowList[index] = flag;
|
||||
}
|
||||
|
||||
public void SetDataButton(int index,Button btn)
|
||||
public void SetDataButton(int index, Button btn)
|
||||
{
|
||||
if (index < 0 || index > dataBtnList.Count - 1)
|
||||
{
|
||||
@@ -93,9 +93,9 @@ namespace xcharts
|
||||
}
|
||||
}
|
||||
|
||||
public void SetShowData(string name,bool flag)
|
||||
public void SetShowData(string name, bool flag)
|
||||
{
|
||||
for(int i = 0; i < dataList.Count; i++)
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
if (dataList[i].Equals(name))
|
||||
{
|
||||
@@ -212,12 +212,20 @@ namespace xcharts
|
||||
|
||||
public float GetData(int index)
|
||||
{
|
||||
if (index >=0 && index <= dataList.Count - 1)
|
||||
if (index >= 0 && index <= dataList.Count - 1)
|
||||
{
|
||||
return dataList[index];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void UpdataData(int index, float value)
|
||||
{
|
||||
if (index >= 0 && index <= dataList.Count - 1)
|
||||
{
|
||||
dataList[index] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class BaseChart : MaskableGraphic
|
||||
@@ -277,7 +285,7 @@ namespace xcharts
|
||||
{
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
if (seriesList[i].name == legend)
|
||||
if (seriesList[i].name.Equals(legend))
|
||||
{
|
||||
seriesList[i].AddData(value);
|
||||
break;
|
||||
@@ -286,6 +294,32 @@ namespace xcharts
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public void UpdateData(string legend, float value, int dataIndex = 0)
|
||||
{
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
if (seriesList[i].name.Equals(legend))
|
||||
{
|
||||
seriesList[i].UpdataData(dataIndex, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public void UpdateData(int legendIndex, float value, int dataIndex = 0)
|
||||
{
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
if (i == legendIndex)
|
||||
{
|
||||
seriesList[i].UpdataData(dataIndex, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public void UpdateTheme(Theme theme)
|
||||
{
|
||||
this.theme = theme;
|
||||
@@ -355,7 +389,7 @@ namespace xcharts
|
||||
Button btn = ChartUtils.AddButtonObject(LEGEND_TEXT + i, transform, themeInfo.font,
|
||||
themeInfo.textColor, Vector2.zero, Vector2.zero, Vector2.zero,
|
||||
new Vector2(legend.itemWidth, legend.itemHeight));
|
||||
legend.SetDataButton(i,btn);
|
||||
legend.SetDataButton(i, btn);
|
||||
Color bcolor = themeInfo.GetColor(i);
|
||||
btn.gameObject.SetActive(legend.show);
|
||||
btn.transform.localPosition = GetLegendPosition(i);
|
||||
@@ -363,8 +397,8 @@ namespace xcharts
|
||||
btn.GetComponentInChildren<Text>().text = legend.dataList[i];
|
||||
btn.onClick.AddListener(delegate ()
|
||||
{
|
||||
legend.SetShowData(i,!legend.IsShowSeries(i));
|
||||
btn.GetComponent<Image>().color = legend.IsShowSeries(i) ?
|
||||
legend.SetShowData(i, !legend.IsShowSeries(i));
|
||||
btn.GetComponent<Image>().color = legend.IsShowSeries(i) ?
|
||||
themeInfo.GetColor(i) : themeInfo.unableColor;
|
||||
OnYMaxValueChanged();
|
||||
OnLegendButtonClicked();
|
||||
@@ -375,7 +409,7 @@ namespace xcharts
|
||||
|
||||
private void InitTooltip()
|
||||
{
|
||||
GameObject obj = ChartUtils.AddTooltipObject("tooltip", transform,themeInfo.font);
|
||||
GameObject obj = ChartUtils.AddTooltipObject("tooltip", transform, themeInfo.font);
|
||||
tooltip.SetObj(obj);
|
||||
tooltip.SetBackgroundColor(themeInfo.tooltipBackgroundColor);
|
||||
tooltip.SetTextColor(themeInfo.tooltipTextColor);
|
||||
@@ -496,7 +530,7 @@ namespace xcharts
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||
Input.mousePosition, null, out local))
|
||||
return;
|
||||
|
||||
|
||||
if (local.x < 0 || local.x > chartWid ||
|
||||
local.y < 0 || local.y > chartHig)
|
||||
return;
|
||||
@@ -598,4 +632,3 @@ namespace xcharts
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace xcharts
|
||||
{
|
||||
float value = series.dataList[i];
|
||||
|
||||
Vector3 p = new Vector3(startX + i * scaleWid,
|
||||
Vector3 p = new Vector3(startX + i * scaleWid,
|
||||
zeroY + value * coordinateHig / max);
|
||||
float pointWid = lineInfo.pointWid;
|
||||
if (tooltip.show && i == tooltip.DataIndex - 1)
|
||||
@@ -106,8 +106,8 @@ namespace xcharts
|
||||
}
|
||||
if (theme == Theme.Dark)
|
||||
{
|
||||
|
||||
ChartUtils.DrawCricle(vh, p, pointWid, color,
|
||||
|
||||
ChartUtils.DrawCricle(vh, p, pointWid, color,
|
||||
(int)lineInfo.pointWid * 5);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -52,11 +52,11 @@ namespace xcharts
|
||||
float degree = totalDegree * value / dataTotal;
|
||||
float toDegree = startDegree + degree;
|
||||
|
||||
float outSideRadius = pieInfo.outsideRadiusDynamic ?
|
||||
pieInfo.insideRadius + (pieRadius - pieInfo.insideRadius) * value / dataMax :
|
||||
float outSideRadius = pieInfo.outsideRadiusDynamic ?
|
||||
pieInfo.insideRadius + (pieRadius - pieInfo.insideRadius) * value / dataMax :
|
||||
pieRadius;
|
||||
ChartUtils.DrawDoughnut(vh, new Vector3(pieCenterX, pieCenterY), pieInfo.insideRadius,
|
||||
outSideRadius,startDegree, toDegree, themeInfo.GetColor(i));
|
||||
ChartUtils.DrawDoughnut(vh, new Vector3(pieCenterX, pieCenterY), pieInfo.insideRadius,
|
||||
outSideRadius, startDegree, toDegree, themeInfo.GetColor(i));
|
||||
startDegree = toDegree;
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ namespace xcharts
|
||||
private float GetDataTotal()
|
||||
{
|
||||
float total = 0;
|
||||
for(int i = 0; i < seriesList.Count; i++)
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
if (legend.IsShowSeries(i))
|
||||
{
|
||||
@@ -83,9 +83,9 @@ namespace xcharts
|
||||
private float GetDataMax()
|
||||
{
|
||||
float max = 0;
|
||||
for(int i = 0; i < seriesList.Count; i++)
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
if(legend.IsShowSeries(i) && seriesList[i].GetData(0) > max)
|
||||
if (legend.IsShowSeries(i) && seriesList[i].GetData(0) > max)
|
||||
{
|
||||
max = seriesList[i].GetData(0);
|
||||
}
|
||||
@@ -98,7 +98,7 @@ namespace xcharts
|
||||
float diffX = chartWid - pieInfo.left - pieInfo.right;
|
||||
float diffY = chartHig - pieInfo.top - pieInfo.bottom;
|
||||
float diff = Mathf.Min(diffX, diffY);
|
||||
if(pieInfo.outsideRadius <= 0)
|
||||
if (pieInfo.outsideRadius <= 0)
|
||||
{
|
||||
pieRadius = diff / 3 * 2;
|
||||
pieCenterX = pieInfo.left + pieRadius;
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace xcharts
|
||||
{
|
||||
public bool cricle;
|
||||
public bool area;
|
||||
|
||||
|
||||
public float radius = 100;
|
||||
public int splitNumber = 5;
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace xcharts
|
||||
else if (diff > 1f)
|
||||
{
|
||||
anchor = TextAnchor.MiddleLeft;
|
||||
pos = new Vector3(pos.x + txtWid + 5,pos.y);
|
||||
pos = new Vector3(pos.x + txtWid + 5, pos.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -100,7 +100,7 @@ namespace xcharts
|
||||
|
||||
private void CheckRadarInfoChanged()
|
||||
{
|
||||
if( checkRadarInfo.radius != radarInfo.radius ||
|
||||
if (checkRadarInfo.radius != radarInfo.radius ||
|
||||
checkRadarInfo.left != radarInfo.left ||
|
||||
checkRadarInfo.right != radarInfo.right ||
|
||||
checkRadarInfo.top != radarInfo.top ||
|
||||
@@ -132,7 +132,7 @@ namespace xcharts
|
||||
var x = radarCenterX + radarInfo.radius * Mathf.Sin(angle);
|
||||
var y = radarCenterY + radarInfo.radius * Mathf.Cos(angle);
|
||||
|
||||
return new Vector3(x,y);
|
||||
return new Vector3(x, y);
|
||||
}
|
||||
|
||||
protected override void DrawChart(VertexHelper vh)
|
||||
@@ -181,13 +181,13 @@ namespace xcharts
|
||||
Vector3 startPoint = Vector3.zero;
|
||||
Vector3 toPoint = Vector3.zero;
|
||||
Vector3 firstPoint = Vector3.zero;
|
||||
|
||||
|
||||
for (int i = 0; i < seriesList.Count; i++)
|
||||
{
|
||||
if (!legend.IsShowSeries(i)) continue;
|
||||
var dataList = seriesList[i].dataList;
|
||||
var color = themeInfo.GetColor(i);
|
||||
var areaColor = new Color(color.r,color.g,color.b,color.a*0.7f);
|
||||
var areaColor = new Color(color.r, color.g, color.b, color.a * 0.7f);
|
||||
var max = radarInfo.indicatorList[i].max > 0 ?
|
||||
radarInfo.indicatorList[i].max :
|
||||
GetMaxValue();
|
||||
@@ -233,11 +233,11 @@ namespace xcharts
|
||||
float block = radarInfo.radius / radarInfo.splitNumber;
|
||||
int indicatorNum = radarInfo.indicatorList.Count;
|
||||
Vector3 p1, p2, p3, p4;
|
||||
Vector3 p = new Vector3(radarCenterX,radarCenterY);
|
||||
Vector3 p = new Vector3(radarCenterX, radarCenterY);
|
||||
float angle = 2 * Mathf.PI / indicatorNum;
|
||||
for (int i = 0; i < radarInfo.splitNumber; i++)
|
||||
{
|
||||
Color color = radarInfo.backgroundColorList[i% radarInfo.backgroundColorList.Count];
|
||||
Color color = radarInfo.backgroundColorList[i % radarInfo.backgroundColorList.Count];
|
||||
outsideRadius = insideRadius + block;
|
||||
p1 = new Vector3(p.x + insideRadius * Mathf.Sin(0), p.y + insideRadius * Mathf.Cos(0));
|
||||
p2 = new Vector3(p.x + outsideRadius * Mathf.Sin(0), p.y + outsideRadius * Mathf.Cos(0));
|
||||
@@ -261,7 +261,7 @@ namespace xcharts
|
||||
float currAngle = j * angle;
|
||||
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
ChartUtils.DrawLine(vh, p, p3, radarInfo.lineTickness/2, radarInfo.lineColor);
|
||||
ChartUtils.DrawLine(vh, p, p3, radarInfo.lineTickness / 2, radarInfo.lineColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ namespace xcharts
|
||||
for (int j = 0; j <= indicatorNum; j++)
|
||||
{
|
||||
float currAngle = j * angle;
|
||||
p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
|
||||
p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
|
||||
p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
ChartUtils.DrawLine(vh, p, p1, radarInfo.lineTickness / 2, radarInfo.lineColor);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user