将 Infragistics UltraChart(线图)绑定到 DataView

发布于 2024-11-05 13:53:46 字数 1140 浏览 4 评论 0原文

我试图通过其 NumericTimeSeriesDataAppearance 实例将 DataView 绑定到 NumericTimeSeries,但该系列最终有零点。我正在使用以下代码进行测试:

DataTable table = new DataTable();
table.Columns.Add("date", typeof(DateTime));
table.Columns.Add("value", typeof(double));

DataView view = new DataView(table);
view.AllowDelete = true;
view.AllowNew = true;
view.AllowEdit = true;

NumericTimeSeries series = new NumericTimeSeries();
series.Data.TimeValueColumn = "date";
series.Data.ValueColumn = "value";
series.Data.DataSource = view;
series.DataBind();

// Update series when data is changed
view.ListChanged += (sender, args) => series.DataBind();
table.RowChanged += (sender, args) => series.DataBind();
table.TableNewRow += (sender, args) => series.DataBind();
table.RowDeleted += (sender, args) => series.DataBind();

table.Rows.Add(DateTime.Now, 42.0);

System.Console.WriteLine("Number of datapoints in view is {0}", view.Count);            
System.Console.WriteLine("Number of datapoints in series is {0}", series.Points.Count);

这会为视图输出 1 个数据点,但为系列输出 0 个数据点。直接绑定到 DataTable 效果很好,但不足以解决我的问题(我正在使用 DataView 按日期对 DataTable 进行排序)。

I'm trying to bind a DataView to NumericTimeSeries through its NumericTimeSeriesDataAppearance instance, but the series end up having zero points. I'm testing using the following code:

DataTable table = new DataTable();
table.Columns.Add("date", typeof(DateTime));
table.Columns.Add("value", typeof(double));

DataView view = new DataView(table);
view.AllowDelete = true;
view.AllowNew = true;
view.AllowEdit = true;

NumericTimeSeries series = new NumericTimeSeries();
series.Data.TimeValueColumn = "date";
series.Data.ValueColumn = "value";
series.Data.DataSource = view;
series.DataBind();

// Update series when data is changed
view.ListChanged += (sender, args) => series.DataBind();
table.RowChanged += (sender, args) => series.DataBind();
table.TableNewRow += (sender, args) => series.DataBind();
table.RowDeleted += (sender, args) => series.DataBind();

table.Rows.Add(DateTime.Now, 42.0);

System.Console.WriteLine("Number of datapoints in view is {0}", view.Count);            
System.Console.WriteLine("Number of datapoints in series is {0}", series.Points.Count);

This outputs 1 datapoint for the view, but 0 for the series. Binding directly to the DataTable works fine, but isn't sufficient for my problem (I'm using a DataView to sort a DataTable on date).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生漫 2024-11-12 13:53:46

我最终使用事件触发器 DataTable.RowChanged、TableNewRow 和 RowDeleted 更新 NumericTimeSeries:

    public void BindSortedViewToSeries(DataTable unsortedTable, DataView sortedView, NumericTimeSeries series)
    {
        unsortedTable.RowChanged += (sender, args) => MirrorDataView(sortedView, series);
        unsortedTable.TableNewRow += (sender, args) => MirrorDataView(sortedView, series);
        unsortedTable.RowDeleted += (sender, args) => MirrorDataView(sortedView, series);
        MirrorDataView(view, series);
    }

    private static void MirrorDataView(DataView view, NumericTimeSeries series)
    {
        series.Data.DataSource = view.ToTable();
        series.DataBind();
    }

I ended up using a trigger for events DataTable.RowChanged, TableNewRow and RowDeleted updating the NumericTimeSeries:

    public void BindSortedViewToSeries(DataTable unsortedTable, DataView sortedView, NumericTimeSeries series)
    {
        unsortedTable.RowChanged += (sender, args) => MirrorDataView(sortedView, series);
        unsortedTable.TableNewRow += (sender, args) => MirrorDataView(sortedView, series);
        unsortedTable.RowDeleted += (sender, args) => MirrorDataView(sortedView, series);
        MirrorDataView(view, series);
    }

    private static void MirrorDataView(DataView view, NumericTimeSeries series)
    {
        series.Data.DataSource = view.ToTable();
        series.DataBind();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文