【问题标题】:Updating telerik chart when data change数据更改时更新 Telerik 图表
【发布时间】:2012-02-10 11:12:56
【问题描述】:

我有一个缓冲区列表,我显示在 Telerik radchart 中。 它显示正确,但是当一个(或多个)缓冲区更新时,我想更新图表以反映新状态。 我唯一能做的就是从头开始重新创建图表,这是一个非常简单的解决方案,但不是很聪明...... 所以我的问题是,是否有一个特殊的 RadChart 类型或某些选项可以设置为在映射为 DataSeries 的集合之一更改时让图表自动更新。 有人可以帮忙吗?

这是我用来创建图表的代码:

private void createChart()
    {
        //Set axis stuff and clear old configuration here

            //Create a dataseries for each values to draw
           foreach (ChannelKeyValueConfiguration channelKeyValue in this.Device.Configuration.ChannelConfigurations)
                {

                    IChannel channel = this.Device.Channels[channelKeyValue.Name];

                    DataSeries serie = new DataSeries();
                    serie.Definition = new LineSeriesDefinition();
                    serie.LegendLabel = channel.Description;

                    int i = 0;
                    int elNumber = channel.Measure.Buffer.Count;   //Neeeded to set xAxis values
                    DateTime minTime = channel.Measure.TimeStamp.Value.AddMilliseconds(-1 * elNumber * channel.Measure.PollingTime);   //Neeeded to set xAxis values

                    foreach (double point in channel.Measure.Buffer)   //Buffer is a Queue<T> that i use as data provider. It updates each x seconds.
                    {
                        i++;
                        serie.Add(new DataPoint() { XValue = minTime.AddMilliseconds( i * channel.Measure.PollingTime).ToOADate(), YValue = point });
                    }

                    RadTimeChart.DefaultView.ChartArea.DataSeries.Add(serie);
                }
            }

然后我有一个应该更新图表的事件处理程序。因为我不知道如何实现它,所以它只是重新创建它以便更新。

void StatusChanged(object sender, EventArgs e)
    {
        Dispatcher.BeginInvoke(new Action(delegate
        {
            createChart();
        }));
    }

请提供一些关于如何更好地处理更新的想法。 提前致谢!

【问题讨论】:

    标签: c#-4.0 telerik


    【解决方案1】:

    经过大量搜索和测试后,我发现 Telerik 的图表很慢,如果您不使用 Queue 绘制图表,有时使用的内存会开始急剧增加。 然而,他们确实提供了一些非常好的 examples in their site,比如 Live Data 示例,这正是我想要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-13
      • 2016-12-18
      • 1970-01-01
      • 2010-12-05
      • 1970-01-01
      相关资源
      最近更新 更多