在我目前的项目中,我有一个生成数据的算法,这些数据将显示在线形图中,但是图表只会在算法结束时更新,而不是在每个“步骤”之后更新。
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++;
}
}
}既然我每一步都调用绘图函数,为什么它只在所有步骤完成后才显示出来?
发布于 2016-09-04 22:40:22
您已经将代码放入了一个类似for循环的循环中
发布于 2016-09-05 02:56:08
在每个图纸之后,更新您的图表。即
drawchart(shares);
cHshares.Update();
k++;我希望这将是有用的。
https://stackoverflow.com/questions/39317772
复制相似问题