【发布时间】:2016-09-04 14:08:22
【问题描述】:
在我当前的项目中,我有一个生成数据的算法,这些数据将显示在折线图中,但是图表仅在算法结束后更新,而不是在每个“步骤”之后更新。
private void simulate(share[] shares)
{
int k = 0;
Random r = new Random(); //random values just for testing
while (k < 10)//10 steps (10 values for each share)
{
for (int i = 0; i < shares.Length; i++)
{
shares[i].value = r.Next(0, 10000);//random a new value
shares[i].history.Add(shares[i].value);//add the value to the value history
}
//now update the chart so that it first shows only one x point than two and so on
drawchart(shares);
k++;
}
}
private void drawchart(share[] shares)
{
cHshares.Series.Clear();//clear the chart
for (int i = 0; i < shares.Length; i++)//for each share
{
cHshares.Series.Add(shares[i].name);//add a new share to the chart
cHshares.Series[shares[i].name].ChartType = SeriesChartType.FastLine;
int j = 0;
//draw the lines with each value that exists for each share
foreach (double value in shares[i].history)
{
cHshares.Series[shares[i].name].Points.AddXY(j, value);
j++;
}
}
}
既然我每一步都调用drawchart funktion,为什么它只在所有步骤完成后才显示?
【问题讨论】:
-
也许刷新图表会有所帮助。
-
我没有名为 refresh() 的方法,我知道存在这样的文档,但即使添加了必需的命名空间,它仍然说图表不包含刷新的定义。
-
好吧c#是区分大小写的,所以方法是
cHshares.Refresh();!您确实意识到您正在删除drawchart方法中的所有系列,对,没有任何延迟.. -
哦,谢谢。我不习惯区分大小写,因为我不经常使用 c#。绘图功能不仅由模拟调用,因此在添加我要显示的图形之前它会自行清除。无论如何,现在它可以工作了,非常感谢你。
标签: c# visual-studio charts real-time