增加数据更新接口UpdateData

This commit is contained in:
monitor1394
2019-03-16 07:49:36 +08:00
parent e62a3775eb
commit 11931e6350
6 changed files with 76 additions and 43 deletions

View File

@@ -218,6 +218,14 @@ namespace xcharts
} }
return 0; return 0;
} }
public void UpdataData(int index, float value)
{
if (index >= 0 && index <= dataList.Count - 1)
{
dataList[index] = value;
}
}
} }
public class BaseChart : MaskableGraphic public class BaseChart : MaskableGraphic
@@ -277,7 +285,7 @@ namespace xcharts
{ {
for (int i = 0; i < seriesList.Count; i++) for (int i = 0; i < seriesList.Count; i++)
{ {
if (seriesList[i].name == legend) if (seriesList[i].name.Equals(legend))
{ {
seriesList[i].AddData(value); seriesList[i].AddData(value);
break; break;
@@ -286,6 +294,32 @@ namespace xcharts
RefreshChart(); 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) public void UpdateTheme(Theme theme)
{ {
this.theme = theme; this.theme = theme;
@@ -598,4 +632,3 @@ namespace xcharts
} }
} }
} }