相关疑难解决方法(0)

Chart DataBinding to DataTable - 图表未更新

我正试图将a数据绑定Chart到a DataTable.我希望图表在添加时显示新行,但是当向表中添加新行时,图表不会更新.我已经验证了两者tabletableDataSource包含新行,但从chart.Series["TestTable"].Points.Count不更改5.

基于问题的示例代码无法将数据表绑定到Chart Control,如下所示.我想知道下面的代码是否有错误或遗漏,或者是一种实现相同目标的不同的更好的方法.我知道如何手动添加点到a Series,但我想看看如何使用数据绑定来做到这一点.

Random r = new Random();
Timer timer = new Timer();
DataTable table = new DataTable("TestTable");
DateTime date = new DateTime(2013, 1, 1);
IList tableDataSource = null;

void timer_Tick(object sender, EventArgs e)
{
    table.Rows.Add(date, r.NextDouble());
    date = date.AddDays(1);

    chart.Update();
}

void MainForm_Load(object sender, EventArgs e)
{
    table.Columns.Add("Date", typeof(DateTime));
    table.Columns.Add("Percent", typeof(double));

    for (int i = 0; i < 5; i++)
    {
        table.Rows.Add(date, r.NextDouble()); …
Run Code Online (Sandbox Code Playgroud)

c# data-binding charts winforms

4
推荐指数
1
解决办法
3万
查看次数

标签 统计

c# ×1

charts ×1

data-binding ×1

winforms ×1