首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >实时图表更新

实时图表更新
EN

Stack Overflow用户
提问于 2016-09-04 22:08:22
回答 2查看 1.2K关注 0票数 0

在我目前的项目中,我有一个生成数据的算法,这些数据将显示在线形图中,但是图表只会在算法结束时更新,而不是在每个“步骤”之后更新。

代码语言:javascript
复制
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++;
        }
    }
}

既然我每一步都调用绘图函数,为什么它只在所有步骤完成后才显示出来?

EN

回答 2

Stack Overflow用户

发布于 2016-09-04 22:40:22

您已经将代码放入了一个类似for循环的循环中

票数 0
EN

Stack Overflow用户

发布于 2016-09-05 02:56:08

在每个图纸之后,更新您的图表。即

代码语言:javascript
复制
drawchart(shares);
cHshares.Update();
k++;

我希望这将是有用的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39317772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档