Chart DataBinding to DataTable - Chart Not Updating

后端 未结 1 1491
隐瞒了意图╮
隐瞒了意图╮ 2020-12-09 14:24

I\'m attempting to databind a Chart to a DataTable. I would like the chart to display new rows as they are added, but the chart is not updating whe

相关标签:
1条回答
  • 2020-12-09 15:03

    Try using the table as a DataSource instead:

    // tableDataSource = (table as IListSource).GetList();
    // chart.DataBindTable(tableDataSource, "Date");
    
    chart.Series.Add("test");
    chart.Series["test"].XValueMember = "Date";
    chart.Series["test"].YValueMembers = "Percent";
    chart.DataSource = table;
    chart.DataBind();
    

    and then in the tick event, call DataBind again instead of the Update:

    void timer_Tick(object sender, EventArgs e) {
      table.Rows.Add(date, r.NextDouble());
      date = date.AddDays(1);
    
      //chart.Update();
      chart.DataBind();
    }
    
    0 讨论(0)
提交回复
热议问题